- def __init__(self, *args, request=None, **kwargs):
- super(ScheduleForm, self).__init__(*args, **kwargs)
- self.request = request
- self.fields['plan'].empty_label = None
-
- 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)
+ def __init__(self, referer=None, **kwargs):
+ self.referer = referer
+ super().__init__(**kwargs)
+
+ def clean_amount(self):
+ value = self.cleaned_data['amount']
+ club = models.Club.objects.first()
+ if club and value < club.min_amount:
+ raise forms.ValidationError(
+ _('Minimal amount is %(amount)d PLN.') % {
+ 'amount': club.min_amount
+ }
+ )
+ return value
+
+ def save(self, *args, **kwargs):
+ NewsletterForm.save(self, *args, **kwargs)
+ self.instance.source = self.referer or ''
+ return super().save(*args, **kwargs)