X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/e15b74e6d8f736dfc8a6101e8b9c6583eebd7509..74f7584b18b4386433b4c02336f5adafcae530c5:/src/club/forms.py diff --git a/src/club/forms.py b/src/club/forms.py index 2664fa353..d1bebe85a 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -5,7 +5,7 @@ from decimal import Decimal from django import forms from django.utils.translation import ugettext as _ from newsletter.forms import NewsletterForm -from . import models +from . import models, payment_methods from .payu.forms import CardTokenForm @@ -14,10 +14,11 @@ class ScheduleForm(forms.ModelForm, NewsletterForm): class Meta: model = models.Schedule - fields = ['monthly', 'amount', 'email'] + fields = ['monthly', 'amount', 'email', 'method'] widgets = { 'amount': forms.HiddenInput, 'monthly': forms.HiddenInput, + 'method': forms.HiddenInput, } def __init__(self, referer=None, **kwargs): @@ -35,6 +36,18 @@ class ScheduleForm(forms.ModelForm, NewsletterForm): ) return value + def clean_method(self): + value = self.cleaned_data['method'] + monthly = self.cleaned_data['monthly'] + for m in payment_methods.methods: + if m.slug == value: + if (monthly and m.is_recurring) or (not monthly and m.is_onetime): + return value + if monthly: + return payment_methods.recurring_payment_method.slug + else: + return payment_methods.single_payment_method.slug + def save(self, *args, **kwargs): NewsletterForm.save(self, *args, **kwargs) self.instance.source = self.referer or ''