diff --git a/input/forms.py b/input/forms.py
index 0ee0237..bdc71ee 100755
--- a/input/forms.py
+++ b/input/forms.py
@@ -156,38 +156,16 @@ class CheckForm(FdbForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.fields['check'] = BooleanField(
- required=True,
- label=format_html(
+
+ # Check if the model field 'terms_accepted' is present
+ if 'terms_accepted' in self.fields:
+ # Make the field required (HTML5 validation)
+ self.fields['terms_accepted'].required = True
+ # Set custom label with link to terms
+ self.fields['terms_accepted'].label = format_html(
"Ich stimme den Nutzungsbedingungen zu",
self.termstoaccept
)
- )
-
- def save(self, commit=True):
- """Save the form instance and map the 'check' field to the model's 'terms_accepted' field, saving to the database if commit=True."""
- # Call the parent form's save() method with commit=False
- # to get a model instance without saving it to the database yet.
- instance = super().save(commit=False)
-
- # If the model has a "terms_accepted" field,
- # copy the value from the form field "check" into it.
- if hasattr(instance, "terms_accepted"):
- instance.terms_accepted = bool(self.cleaned_data.get('check'))
-
- # If commit=True (default), save the instance to the database now.
- if commit:
- instance.save()
-
- # Return the model instance (saved if commit=True, otherwise unsaved).
- return instance
-
- """Baseclass for all classes which need a check for Nutzungsbedingungen"""
-# def __init__(self, *args, **kwargs):
-# check = BooleanField(required=True,
-# label=format_html("Ich stimme den Nutzungsbedingungen zu",
-# termstoaccept))
-# NUTZUNGSBEDINGUNGEN))
class LiteratureForm(CheckForm):
@@ -198,7 +176,7 @@ class LiteratureForm(CheckForm):
self.fields['selfbuy_give_data'].required = True
class Meta:
model = Literature
- fields = ['cost', 'info', 'source', 'notes', 'selfbuy', 'selfbuy_data', 'selfbuy_give_data']
+ fields = ['cost', 'info', 'source', 'notes', 'selfbuy', 'selfbuy_data', 'selfbuy_give_data', 'terms_accepted']
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
class Media:
js = ('dropdown/js/literature.js',)
@@ -225,7 +203,7 @@ class EmailForm(CheckForm):
# TODO: add some javascript to show/hide other-field
class Meta:
model = Email
- fields = ['domain', 'address', 'other', 'adult']
+ fields = ['domain', 'address', 'other', 'adult', 'terms_accepted']
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
class Media:
js = ('dropdown/js/mail.js',)
@@ -243,7 +221,7 @@ class BusinessCardForm(CheckForm):
class Meta:
model = BusinessCard
exclude = ['intern_notes', 'survey_mail_send', 'mail_state']
- fields = ['project', 'data', 'variant', 'url_of_pic', 'send_data_to_print', 'sent_to']
+ fields = ['project', 'data', 'variant', 'url_of_pic', 'send_data_to_print', 'sent_to', 'terms_accepted']
class Media:
js = ('dropdown/js/businessCard.js',)
@@ -252,5 +230,5 @@ class ListForm(CheckForm):
termstoaccept = settings.NUTZUNGSBEDINGUNGEN_MAILINGLISTEN
class Meta:
model = List
- fields = ['domain', 'address']
+ fields = ['domain', 'address', 'terms_accepted']
exclude = ['intern_notes', 'survey_mail_send','mail_state']