1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from decimal import Decimal
5 from django import forms
6 from newsletter.forms import NewsletterForm
8 from .payu.forms import CardTokenForm
11 class ScheduleForm(forms.ModelForm, NewsletterForm):
13 model = models.Schedule
14 fields = ['monthly', 'amount', 'email']
16 'amount': forms.HiddenInput,
17 'monthly': forms.HiddenInput,
20 def clean_amount(self):
21 value = self.cleaned_data['amount']
22 club = models.Club.objects.first()
23 if club and value < club.min_amount:
24 raise forms.ValidationError('Minimalna kwota to %d zł.' % club.min_amount)
27 def save(self, *args, **kwargs):
28 NewsletterForm.save(self, *args, **kwargs)
29 return super().save(*args, **kwargs)
32 class PayUCardTokenForm(CardTokenForm):
33 def get_queryset(self, view):
34 return view.get_schedule().payucardtoken_set