2 from django import forms
5 from .payment_methods import method_by_slug
8 class ScheduleForm(forms.ModelForm):
10 model = models.Schedule
11 fields = ['plan', 'method', 'amount', 'email']
13 'plan': forms.RadioSelect,
14 'method': forms.RadioSelect,
17 def __init__(self, *args, **kwargs):
18 super(ScheduleForm, self).__init__(*args, **kwargs)
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)