Fixes #3934: Error on OAI-PMH list request.
[wolnelektury.git] / src / club / forms.py
1 # -*- coding: utf-8
2 from django import forms
3 from . import models
4 from .payment_methods import method_by_slug 
5
6
7 class ScheduleForm(forms.ModelForm):
8     class Meta:
9         model = models.Schedule
10         fields = ['plan', 'method', 'amount', 'email']
11         widgets = {
12             'plan': forms.RadioSelect,
13             'method': forms.RadioSelect,
14         }
15
16     def __init__(self, *args, **kwargs):
17         super(ScheduleForm, self).__init__(*args, **kwargs)
18         self.fields['plan'].empty_label = None
19
20     def clean(self):
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)
28