1 from django import forms
3 from .payment_methods import method_by_slug
4 from .payu.forms import CardTokenForm
7 class ScheduleForm(forms.ModelForm):
9 model = models.Schedule
10 fields = ['plan', 'method', 'amount', 'email']
12 'plan': forms.RadioSelect,
13 'method': forms.RadioSelect,
16 def __init__(self, *args, request=None, **kwargs):
17 super(ScheduleForm, self).__init__(*args, **kwargs)
18 self.request = request
19 self.fields['plan'].empty_label = None
22 cleaned_data = super(ScheduleForm, self).clean()
23 if 'method' in cleaned_data:
24 method = method_by_slug[cleaned_data['method']]
25 if method not in cleaned_data['plan'].payment_methods():
26 self.add_error('method', 'Metoda płatności niedostępna dla tego planu.')
27 if cleaned_data['amount'] < cleaned_data['plan'].min_amount:
28 self.add_error('amount', 'Minimalna kwota dla tego planu to %d zł.' % cleaned_data['plan'].min_amount)
31 class PayUCardTokenForm(CardTokenForm):
32 def get_queryset(self, view):
33 return view.get_schedule().payucardtoken_set