1. Allan Davis
  2. pixels_for_food

Source

pixels_for_food / pixels / views.py

# Create your views here.
from django.shortcuts import render_to_response
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]
    #if(cause.donations):
    #    donations = cause.donations.objects.order_by('-donation_date')[:20]
    #else:
    #    donations = []
    params = {
        "cause": cause,
        #"donations": donations,
        }
    return render_to_response("index.html", params )

def checkout(request):
    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,        
    }
    return render_to_response("checkout.html", params)