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 django.utils.translation import ugettext as _
7 from newsletter.forms import NewsletterForm
9 from .payu.forms import CardTokenForm
12 class ScheduleForm(forms.ModelForm, NewsletterForm):
14 model = models.Schedule
15 fields = ['monthly', 'amount', 'email']
17 'amount': forms.HiddenInput,
18 'monthly': forms.HiddenInput,
21 def clean_amount(self):
22 value = self.cleaned_data['amount']
23 club = models.Club.objects.first()
24 if club and value < club.min_amount:
25 raise forms.ValidationError(
26 _('Minimal amount is %(amount)d PLN.') % {
27 'amount': club.min_amount
32 def save(self, *args, **kwargs):
33 NewsletterForm.save(self, *args, **kwargs)
34 return super().save(*args, **kwargs)
37 class PayUCardTokenForm(CardTokenForm):
38 def get_queryset(self, view):
39 return view.get_schedule().payucardtoken_set