X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8d1372958ce4a205f11fcdd44cf6e9cac8429a69..575e58df64c98b53edca9fb6a29b284dbc375609:/apps/funding/forms.py diff --git a/apps/funding/forms.py b/apps/funding/forms.py new file mode 100755 index 000000000..eb75fb6f1 --- /dev/null +++ b/apps/funding/forms.py @@ -0,0 +1,30 @@ +from django import forms +from .models import Offer + + +class DummyForm(forms.Form): + amount = forms.DecimalField() + name = forms.CharField() + email = forms.EmailField() + + def __init__(self, offer, *args, **kwargs): + self.offer = offer + super(DummyForm, self).__init__(*args, **kwargs) + + def clean_amount(self): + if self.cleaned_data['amount'] <= 0: + raise forms.ValidationError("A!") + return self.cleaned_data['amount'] + + def clean(self): + if self.offer != Offer.current(): + raise forms.ValidationError("B!") + return self.cleaned_data + + def save(self): + print self.cleaned_data + return self.offer.fund( + name=self.cleaned_data['name'], + email=self.cleaned_data['email'], + amount=self.cleaned_data['amount']) +