+ def __init__(self, referer=None, **kwargs):
+ self.referer = referer
+ super().__init__(**kwargs)
+
+ self.fields['first_name'].required = True
+ self.fields['last_name'].required = True
+ self.fields['phone'].required = True
+
+ self.consent = []
+ for c in models.Consent.objects.filter(active=True).order_by('order'):
+ key = f'consent{c.id}'
+ self.fields[key] = forms.BooleanField(
+ label=c.text,
+ required=c.required
+ )
+ self.consent.append((
+ c, key, (lambda k: lambda: self[k])(key)
+ ))
+
+ 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 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 ''
+ instance = super().save(*args, **kwargs)
+
+ consents = []
+ for consent, key, consent_field in self.consent:
+ if self.cleaned_data[key]:
+ instance.consent.add(consent)
+
+ return instance
+
+
+class PayUCardTokenForm(CardTokenForm):
+ def get_queryset(self, view):
+ return view.get_schedule().payucardtoken_set
+
+
+
+class DonationStep1Form(forms.ModelForm):
+ switch = forms.CharField()
+ single_amount = forms.IntegerField(required=False)
+ monthly_amount = forms.IntegerField(required=False)
+ single_amount_selected = forms.IntegerField(required=False)
+ monthly_amount_selected = forms.IntegerField(required=False)
+ custom_amount = forms.IntegerField(required=False)
+
+ amount = forms.IntegerField(required=False) # hidden
+
+ class Meta:
+ model = models.Schedule
+ fields = [
+ 'amount',
+ 'monthly'
+ ]
+