Commits

Allan Davis committed 3b01b16

Fixed form for input of donator

  • Participants
  • Parent commits b81890b

Comments (0)

Files changed (7)

File pixels/forms.py

 from models import Donation
 from django import forms
 
-class DonationForm (forms.ModelForm):
+class DonationForm (forms.Form):
     """ Form for donations input from external user """
-    class Meta:
-        model = Donation
-        fields = ('name', 'email', 'anonymous', 'amount', )
-        widgets = {
-            'amount' : forms.HiddenInput(),
-        }
+    name = forms.CharField(max_length=100, required=False)
+    email = forms.EmailField(max_length=50, required=False)
+    anonymous = forms.BooleanField()    
+    amount = forms.DecimalField(max_digits=5, decimal_places=2, widget=forms.HiddenInput)
+    pounds = forms.IntegerField(widget=forms.HiddenInput)
+    
 
 

File pixels/models.py

     """ Donation record """
     name = models.CharField(max_length=100, null=True)
     email = models.EmailField(max_length=50, null=True)
-    anonymous = models.BooleanField()
+    anonymous = models.BooleanField()    
+    amount = models.DecimalField(max_digits=5, decimal_places=2)
     donation_date = models.DateTimeField(auto_now_add = True)    
-    amount = models.DecimalField(max_digits=5, decimal_places=2)
     cause = models.ForeignKey("Cause", related_name="donations")
     
     def __unicode__(self):

File pixels/views.py

 from models import Cause
 from models import Donation
 from forms import DonationForm
+from django.http import HttpResponseRedirect
+from django.http import HttpResponseBadRequest
 
 def index(request):
     cause = Cause.objects.filter(active_donation_target=True)[0]
     return render_to_response("index.html", params )
 
 def checkout(request):
-    amount = request.POST['amount']
-    lbs = request.POST['lbs']
-    form = DonationForm() #initial={"amount":amount}
+    if request.method == 'POST':
+        form = DonationForm(request.POST)
+        if form.is_valid():
+            cause = Cause.objects.filter(active_donation_target=True)[0]
+            # populate donation object from form
+            donation = Donation(
+                name=form.cleaned_data['name'],
+                amount=form.cleaned_data['amount'],
+                anonymous = form.cleaned_data['anonymous'],
+                email = form.cleaned_data['email'])
+            donation.cause = cause
+            donation.save()
+            #create url to submit to paypal to complete porcess
+            url = "http://google.com"
+            return HttpResponseRedirect(url)        
+    else:
+        amount = request.GET['amount']
+        lbs = request.GET['lbs']
+        form = DonationForm(initial={"amount":amount, "pounds": lbs}) 
     params = {
-        "form":form,
-        "amount":amount,
-        "pounds":lbs,
-        }
+        "form":form,        
+    }
     return render_to_response("checkout.html", params)
 
-def process(request):
-    pass

File pixels_for_food.kpf

-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Komodo Project File - DO NOT EDIT -->
-<project id="8bef410c-633a-4cc5-b703-56274a1d44cd" kpf_version="4" name="pixels_for_food.kpf">
-<preference-set idref="8bef410c-633a-4cc5-b703-56274a1d44cd">
-  <boolean id="import_live">1</boolean>
-</preference-set>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Komodo Project File - DO NOT EDIT -->
+<project id="8bef410c-633a-4cc5-b703-56274a1d44cd" kpf_version="4" name="pixels_for_food.kpf">
+<preference-set idref="8bef410c-633a-4cc5-b703-56274a1d44cd">
+  <boolean id="import_live">1</boolean>
+</preference-set>
+</project>

File templates/checkout.html

 {% extends "base.html" %}
 
 {% block header %}
+<script language="javascript" type="text/javascript">
+    function donation(){
+        $("#id_anonymous").attr('checked', false);
+        $("#donation_form").submit();
+    }
+    function anon_donation(){
+        $("#id_name").attr("value", "anonymous");
+        $("#id_email").attr("value", "");
+        $("#id_anonymous").attr('checked', true);
+        $("#donation_form").submit();
+    }
+    
+    
+</script>
 {% endblock %}
 
 {%block content %}
 <div id="middleBar">
 <div id="middleBar_Content">
-<h3>You are donating <span id="poundTotal">{{pounds}}</span> lbs of food worth $<span id="total">{{amount}}</span></h3>
+<h3>You are donating <span id="poundTotal">{{form.initial['pounds']}}</span> lbs of food worth $<span id="total">{{form.initial['amount']}}</span></h3>
 </div>
 </div>
 <div id="content" >
-    <form action="process" method="post" >
-        {{ form.as_p }}
-        <p><input type="submit" value="Submit" /></p>
+    
+    <form method="post" id="donation_form">
+        <table border="0" width="50%" align="center" >
+        {{ form.as_table }}
+            <tr>
+                <td align="center"><input type="button" value="Donate" onclick="donation();"/></td>
+                <td align="center"><input type="button" value="Anonymouns Donation" onclick="anon_donation();"/></td>
+            </tr>
+        </table>
     </form>
+    
 </div>
 {% endblock%}

File templates/index.html

     -->
   </div>
   <a href="javascript:checkout();" id="rollover3"><span>Checkout</span></a>
-  <form action="checkout/" method="post" name="checkout_form" id="checkout_form">
+  <form action="checkout/" method="get" name="checkout_form" id="checkout_form">
 	<input type="hidden" name="amount" id="amount" value="" />
 	<input type="hidden" name="lbs" id="lbs" value="" />
   </form>
     # Uncomment the next line to enable the admin:
     (r'^admin/', include(admin.site.urls)),    
     (r'^checkout/', 'pixels.views.checkout'),
-    (r'^process/', 'pixels.views.process'),
+    #(r'^process/', 'pixels.views.process'),
     (r'^', 'pixels.views.index'),
 )