From fb41f1b2fe6f011288a3e94651b02e702d97b0f1 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 1 Feb 2024 13:32:28 +0100 Subject: [PATCH] add 3 checkbox for terms and conditions --- idhub/admin/views.py | 2 +- idhub/templates/idhub/user/profile.html | 7 +++- .../idhub/user/terms_conditions.html | 38 +++++++------------ idhub/user/forms.py | 38 +++++++++++++++++-- idhub/user/views.py | 16 +++++++- 5 files changed, 70 insertions(+), 31 deletions(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 3773cab..77c83b4 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -62,7 +62,7 @@ class TermsAndConditionsView(AdminView, FormView): template_name = "idhub/admin/terms_conditions.html" title = _("GDPR") section = "" - subtitle = _('Accept Terms and Conditions') + subtitle = _('Terms and Conditions') icon = 'bi bi-file-earmark-medical' form_class = TermsConditionsForm success_url = reverse_lazy('idhub:admin_dashboard') diff --git a/idhub/templates/idhub/user/profile.html b/idhub/templates/idhub/user/profile.html index 6efdc48..cfbc4b9 100644 --- a/idhub/templates/idhub/user/profile.html +++ b/idhub/templates/idhub/user/profile.html @@ -11,7 +11,12 @@
- {% trans 'ARCO Forms' %} + {% if lang == 'es' %} + {% trans 'ARCO Forms' %} + {% else %} + {% trans 'ARCO Forms' %} + {% endif %} + {% trans 'Notice of Privacy' %}
diff --git a/idhub/templates/idhub/user/terms_conditions.html b/idhub/templates/idhub/user/terms_conditions.html index 8a02175..f021b4d 100644 --- a/idhub/templates/idhub/user/terms_conditions.html +++ b/idhub/templates/idhub/user/terms_conditions.html @@ -20,38 +20,28 @@ {% endif %} -
+
- You must read the terms and conditions of this service and accept the - Read GDPR + {{ form.accept_privacy }} + {{ form.privacy_label|safe }}
-
-
- {% bootstrap_form form %} +
+
+ {{ form.accept_legal }} + {{ form.legal_label|safe }}
-
+
+
+ {{ form.accept_cookies }} + {{ form.cookies_label|safe }} +
+
+ - - {% endblock %} diff --git a/idhub/user/forms.py b/idhub/user/forms.py index bad06be..0c16171 100644 --- a/idhub/user/forms.py +++ b/idhub/user/forms.py @@ -15,8 +15,16 @@ class ProfileForm(forms.ModelForm): class TermsConditionsForm(forms.Form): - accept = forms.BooleanField( - label=_("Accept terms and conditions of the service"), + accept_privacy = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_legal = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_cookies = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), required=False ) @@ -24,9 +32,33 @@ class TermsConditionsForm(forms.Form): self.user = kwargs.pop('user', None) super().__init__(*args, **kwargs) + def get_label(self, url, read): + label = _('You must read the terms and conditions of this service and accept the') + label += f' {read}' + return label + + def privacy_label(self): + url = "https://laweb.pangea.org/politica-de-privacitat/" + read = _("Read privacy policy") + return self.get_label(url, read) + + def legal_label(self): + url = "https://laweb.pangea.org/avis-legal/" + read = _("Read legal policy") + return self.get_label(url, read) + + def cookies_label(self): + url = "https://laweb.pangea.org/politica-de-cookies-2/" + read = _("Read cookies policy") + return self.get_label(url, read) + def clean(self): data = self.cleaned_data - if data.get("accept"): + privacy = data.get("accept_privacy") + legal = data.get("accept_legal") + cookies = data.get("accept_cookies") + if privacy and legal and cookies: self.user.accept_gdpr = True else: self.user.accept_gdpr = False diff --git a/idhub/user/views.py b/idhub/user/views.py index 82c5337..fcd622d 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -100,6 +100,13 @@ class ProfileView(MyProfile, UpdateView, SingleTableView): def form_valid(self, form): return super().form_valid(form) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'lang': self.request.LANGUAGE_CODE, + }) + return context class RolesView(MyProfile, SingleTableView): @@ -137,7 +144,7 @@ class TermsAndConditionsView(UserView, FormView): template_name = "idhub/user/terms_conditions.html" title = _("GDPR") section = "" - subtitle = _('Accept Terms and Conditions') + subtitle = _('Terms and Conditions') icon = 'bi bi-file-earmark-medical' form_class = TermsConditionsForm success_url = reverse_lazy('idhub:user_dashboard') @@ -145,7 +152,12 @@ class TermsAndConditionsView(UserView, FormView): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['user'] = self.request.user - kwargs['initial'] = {"accept": self.request.user.accept_gdpr} + if self.request.user.accept_gdpr: + kwargs['initial'] = { + "accept_privacy": True, + "accept_legal": True, + "accept_cookies": True + } return kwargs def form_valid(self, form):