Exemple #1
0
def pledge(request):
    if request.method == "POST":  # If the form has been submitted...
        form = PledgeForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            form.save()
            return HttpResponseRedirect("/pledge/")  # Redirect after POST
    else:
        form = PledgeForm()  # An unbound form

    return render(request, "pledges/index.html", {"form": form})

    # def newDonor(request):
    #     if request.method == 'POST': # If the form has been submitted...
    #         form = DonorForm(request.POST) # A form bound to the POST data
    #         if form.is_valid(): # All validation rules pass
    #             # Process the data in form.cleaned_data
    #             # ...
    #             form.save()

    #             return HttpResponseRedirect('/pledge/donor/') # Redirect after POST
    #     else:
    #         form = DonorForm() # An unbound form

    return render(request, "pledges/newdonor.html", {"form": form})
Exemple #2
0
def edit_pledge(request, pledge_id):
    pledge = Pledge.objects.filter(id=pledge_id).first()
    # verify pledge exists
    if not pledge:
        return redirect('profile')
    # verify pledge belongs to user
    if pledge.user != request.user:
        return redirect('access_denied')
    # update pledge
    if request.method == 'POST':
        form = PledgeForm(request.POST, instance=pledge)

        if form.is_valid():
            form.save()
        return redirect('profile')
    else:
        form = PledgeForm(instance=pledge)
        return render(request, 'publicweb/pledge_form.html', {'form': form})