Beispiel #1
0
def register_donations(request):
    contexts = {}
    # Pictureformset = modelformset_factory(Picture, form=PhotoForm, fields=('url',), extra=3)
    if request.method == 'POST':
        # formset = Pictureformset(request.POST, request.FILES)
        form = DonationForm(request.POST)
        if form.is_valid():
            new_form = form.save(commit=False)
            Name = request.POST.get('name')[:3]
            new_form.donor = Doner.objects.get(user=request.user)
            # create album for pic
            if request.FILES.getlist('images'):
                album = Album(name='Album of ' + Name)
                album.save()
                for file in request.FILES.getlist('images'):
                    pic = Picture(name=Name, url=file, album=album)
                    pic.save()
            new_form.album = album
            new_form.save()
            contexts['success'] = 'บันทึกสำเร็จ'
            messages.success(request, 'ลงทะเบียน ' + new_form.name + ' สำเร็จ')
            return redirect('donation_list')
        else:
            contexts['danger'] = 'บันทึกไม่สำเร็จ'
            form = DonationForm()

    else:
        # formset = Pictureformset()
        form = DonationForm()

    contexts['form'] = form
    return render(request,
                  'donations/register_donations.html',
                  context=contexts)
Beispiel #2
0
def make(request):
    credit_card_form = StripeCreditCardForm(request.POST or None,
                                            user=request.user)
    donation_form = DonationForm(request.POST or None, user=request.user)

    if request.method == 'POST' \
            and credit_card_form.is_valid() \
            and donation_form.is_valid():
        # create charge at Stripe
        charge = credit_card_form.charge_customer(
            amount=donation_form.cleaned_data.get('amount'),
            description='Donation from {} to OBY'.format(request.user.email))
        if charge:
            # persist charge ID returned from Stripe
            donation_form.charge_id = charge.id
            donation_form.save()

            messages.success(request, "Thank you for your donation!")
            return HttpResponseRedirect(reverse('donations:info'))

        else:
            messages.error(
                request, "We're sorry, but your credit card "
                "could not be charged at this time. "
                "We regret that this has occured. "
                "Please try again later.")

    context = {
        'credit_card_form': credit_card_form,
        'donation_form': donation_form
    }
    return render(request, 'donations/make.html', context)
Beispiel #3
0
    def post(self, request, *args, **kwargs):

        key_to_check = "{}-amount".format(self.donate_form_prefix)
        if key_to_check in request.POST:
            form = DonationForm(data=request.POST,
                                prefix=self.donate_form_prefix)
            if form.is_valid():
                gc = GoCardlessHelper()
                url = gc.get_payment_url(**form.cleaned_data)
                return HttpResponseRedirect(url)
        return super(FeedbackFormView, self).post(request, *args, **kwargs)
Beispiel #4
0
def home(request):
    if request.method == 'POST':
        form = DonationForm(request.POST)
        if form.is_valid():
            amount = form.cleaned_data['amount']
            nonce = request.POST['payment_method_nonce']
            payment_result = do_payment(amount,nonce)
            form.save()
            return render(request, 'success.html', {'result':payment_result,
                'amount':payment_result,
                })
    else:
        form = DonationForm()
        
    donations = Donations.objects.order_by('-amount')
    campaign = Campaign.objects.all()
    return render(request,"donate.html" ,{
            'BT_CLIENT_KEY':getClientID(),
            'donations':donations,
            'campaigns':campaign,
            'form':form,
        })