X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/967eed676fc83d15b26149047f353ac61faa8217..8952b9530d943655e552ea660c47e850123c5105:/src/club/forms.py?ds=sidebyside diff --git a/src/club/forms.py b/src/club/forms.py index c5d57819e..8df778338 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -1,28 +1,29 @@ -# -*- coding: utf-8 +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from decimal import Decimal from django import forms from . import models -from .payment_methods import method_by_slug +from .payu.forms import CardTokenForm class ScheduleForm(forms.ModelForm): class Meta: model = models.Schedule - fields = ['plan', 'method', 'amount', 'email'] + fields = ['monthly', 'amount', 'email'] widgets = { - 'plan': forms.RadioSelect, - 'method': forms.RadioSelect, + 'amount': forms.HiddenInput, + 'monthly': forms.HiddenInput, } - def __init__(self, *args, **kwargs): - super(ScheduleForm, self).__init__(*args, **kwargs) - self.fields['plan'].empty_label = None + def clean_amount(self): + value = self.cleaned_data['amount'] + club = models.Club.objects.first() + if club and value < club.min_amount: + raise forms.ValidationError('Minimalna kwota to %d zł.' % club.min_amount) + return value - def clean(self): - cleaned_data = super(ScheduleForm, self).clean() - if 'method' in cleaned_data: - method = method_by_slug[cleaned_data['method']] - if method not in cleaned_data['plan'].payment_methods(): - self.add_error('method', 'Metoda płatności niedostępna dla tego planu.') - if cleaned_data['amount'] < cleaned_data['plan'].min_amount: - self.add_error('amount', 'Minimalna kwota dla tego planu to %d zł.' % cleaned_data['plan'].min_amount) +class PayUCardTokenForm(CardTokenForm): + def get_queryset(self, view): + return view.get_schedule().payucardtoken_set