1 from django import forms
2 from django.utils.translation import ugettext_lazy as _, ugettext as __
3 from .models import Funding
4 from .widgets import PerksAmountWidget
7 class DummyForm(forms.Form):
8 required_css_class = 'required'
10 amount = forms.DecimalField(label=_("Amount"), decimal_places=2,
11 widget=PerksAmountWidget())
12 name = forms.CharField(label=_("Name"), required=False)
13 anonymous = forms.BooleanField(label=_("Anonymously"),
15 help_text=_("Check if you don't want your name to be visible publicly."))
16 email = forms.EmailField(label=_("E-mail"),
17 help_text=_("Won't be publicised."), required=False)
19 def __init__(self, offer, *args, **kwargs):
21 super(DummyForm, self).__init__(*args, **kwargs)
22 self.fields['amount'].widget.form_instance = self
24 def clean_amount(self):
25 if self.cleaned_data['amount'] <= 0:
26 raise forms.ValidationError(__("Enter positive amount."))
27 return self.cleaned_data['amount']
30 if not self.offer.is_current():
31 raise forms.ValidationError(__("This offer is out of date."))
32 return self.cleaned_data
35 return Funding.objects.create(
37 name=self.cleaned_data['name'],
38 email=self.cleaned_data['email'],
39 amount=self.cleaned_data['amount'],
40 anonymous=self.cleaned_data['anonymous'],