eb75fb6f11fcfa69c15d2e00b269e8853fb5ef05
[wolnelektury.git] / apps / funding / forms.py
1 from django import forms
2 from .models import Offer
3
4
5 class DummyForm(forms.Form):
6     amount = forms.DecimalField()
7     name = forms.CharField()
8     email = forms.EmailField()
9
10     def __init__(self, offer, *args, **kwargs):
11         self.offer = offer
12         super(DummyForm, self).__init__(*args, **kwargs)
13
14     def clean_amount(self):
15         if self.cleaned_data['amount'] <= 0:
16             raise forms.ValidationError("A!")
17         return self.cleaned_data['amount']
18
19     def clean(self):
20         if self.offer != Offer.current():
21             raise forms.ValidationError("B!")
22         return self.cleaned_data
23
24     def save(self):
25         print self.cleaned_data
26         return self.offer.fund(
27             name=self.cleaned_data['name'],
28             email=self.cleaned_data['email'],
29             amount=self.cleaned_data['amount'])
30