Beispiel #1
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 #2
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 #3
0
    def get_success_url(self):

        feedback_object = self.object
        context = {
            'object':
            feedback_object,
            'donate_form':
            DonationForm(initial={
                'payment_type': 'subscription',
                'amount': 3,
            },
                         prefix="donation_form")
        }

        messages.success(
            self.request,
            render_to_string('feedback/feedback_thanks.html',
                             context,
                             request=self.request),
            extra_tags='template',
        )

        if is_safe_url(self.object.source_url):
            return self.object.source_url
        else:
            return "/"
Beispiel #4
0
    def get_context_data(self, **kwargs):
        ctx = super(PersonalProfileView, self).get_context_data(**kwargs)

        if 'account_form' not in ctx:
            ctx['account_form'] = CustomUserChangeForm(
                self.request, instance=self.request.user)

        if 'donation_form' not in ctx:
            ctx['donation_form'] = DonationForm(self.request)

        return ctx
Beispiel #5
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 #6
0
    def get_context_data(self, **kwargs):
        context = super(ProfileView, self).get_context_data()
        context['user_form'] = UserChangeForm(initial={
            'address': self.request.user.address,
            'phone_number': self.request.user.phone_number,
            'email': self.request.user.email})
        context['password_form'] = PasswordChangeForm(user=self.request.user)
        context['donation_form'] = DonationForm(self.request)
        context['donations'] = Donation.objects.filter(user=self.request.user).order_by('-created_dt')
        context['tokens_sum'] = [Donation.objects.filter(user=self.request.user).order_by('-created_dt').aggregate(Sum('tokens'))['tokens__sum']]
        context['addresses'] = DonationAddress.objects.all()

        return context
Beispiel #7
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,
        })
Beispiel #8
0
    def post(self, request, *args, **kwargs):

        form = None
        ctx_kwargs = {"form": form}

        if request.POST.get('submit', '') == 'account_form':
            form = CustomUserChangeForm(request,
                                        request.POST,
                                        request.FILES,
                                        instance=request.user)
            message = _("Changes saved")
            ctx_kwargs = {"account_form": form}
        elif request.POST.get('submit', '') == 'donation_form':
            form = DonationForm(request, request.POST)
            message = _("Data sent")
            ctx_kwargs = {"donation_form": form}

        if form and form.is_valid():
            form.save()
            messages.info(request, message)
            return redirect('profile')
        else:
            return self.render_to_response(self.get_context_data(**ctx_kwargs))