2 from django import forms
4 from .payment_methods import method_by_slug
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, **kwargs):
17 super(ScheduleForm, self).__init__(*args, **kwargs)
18 self.fields['plan'].empty_label = None
21 cleaned_data = super(ScheduleForm, self).clean()
22 if 'method' in cleaned_data:
23 method = method_by_slug[cleaned_data['method']]
24 if method not in cleaned_data['plan'].payment_methods():
25 self.add_error('method', 'Metoda płatności niedostępna dla tego planu.')
26 if cleaned_data['amount'] < cleaned_data['plan'].min_amount:
27 self.add_error('amount', 'Minimalna kwota dla tego planu to %d zł.' % cleaned_data['plan'].min_amount)