Payment overhaul.
[wolnelektury.git] / src / club / forms.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from decimal import Decimal
5 from django import forms
6 from . import models
7 from .payu.forms import CardTokenForm
8
9
10 class ScheduleForm(forms.ModelForm):
11     class Meta:
12         model = models.Schedule
13         fields = ['monthly', 'amount', 'email']
14         widgets = {
15             'amount': forms.HiddenInput,
16             'monthly': forms.HiddenInput,
17         }
18
19     def clean_amount(self):
20         value = self.cleaned_data['amount']
21         club = models.Club.objects.first()
22         if club and value < club.min_amount:
23             raise forms.ValidationError('Minimalna kwota to %d zł.' % club.min_amount)
24         return value
25
26
27 class PayUCardTokenForm(CardTokenForm):
28     def get_queryset(self, view):
29         return view.get_schedule().payucardtoken_set