+ self.fields['first_name'].required = True
+ self.fields['last_name'].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 save(self, *args, **kwargs):
+ NewsletterForm.save(self, *args, **kwargs)
+ 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