diff --git a/src/dashboard/apps/consent/fixtures/consent.py b/src/dashboard/apps/consent/fixtures/consent.py index c25f632e..742c2105 100644 --- a/src/dashboard/apps/consent/fixtures/consent.py +++ b/src/dashboard/apps/consent/fixtures/consent.py @@ -29,11 +29,11 @@ def seed_consent(): entity4 = EntityFactory(users=(user5,)) # create delivery points - for i in range(1, 4): - DeliveryPointFactory(provider_assigned_id=f"entity1_{i}", entity=entity1) - DeliveryPointFactory(provider_assigned_id=f"entity2_{i}", entity=entity2) - DeliveryPointFactory(provider_assigned_id=f"entity3_{i}", entity=entity3) - DeliveryPointFactory(provider_assigned_id=f"entity4_{i}", entity=entity4) + for _ in range(1, 4): + DeliveryPointFactory(entity=entity1) + DeliveryPointFactory(entity=entity2) + DeliveryPointFactory(entity=entity3) + DeliveryPointFactory(entity=entity4) # create awaiting consents for delivery_point in DeliveryPoint.objects.all(): diff --git a/src/dashboard/apps/consent/forms.py b/src/dashboard/apps/consent/forms.py new file mode 100644 index 00000000..3e94e7b0 --- /dev/null +++ b/src/dashboard/apps/consent/forms.py @@ -0,0 +1,26 @@ +"""Dashboard consent app forms.""" + +from django import forms +from django.forms.widgets import CheckboxInput +from django.utils.translation import gettext_lazy as _ + + +class ConsentCheckboxInput(CheckboxInput): + """Custom CheckboxInput widget for rendering a checkbox input field.""" + + template_name = "consent/forms/widgets/checkbox.html" + + +class ConsentForm(forms.Form): + """Save user consent through a checkbox field.""" + + consent_agreed = forms.BooleanField( + required=True, + initial=False, + widget=ConsentCheckboxInput( + attrs={ + "label": _("I agree to give my consent"), + "help_text": _("Please confirm your consent by checking this box."), + }, + ), + ) diff --git a/src/dashboard/apps/consent/mixins.py b/src/dashboard/apps/consent/mixins.py new file mode 100644 index 00000000..57008202 --- /dev/null +++ b/src/dashboard/apps/consent/mixins.py @@ -0,0 +1,37 @@ +"""Dashboard consent app mixins.""" + +from django.views.generic.base import ContextMixin +from django_stubs_ext import StrOrPromise + + +class BreadcrumbContextMixin(ContextMixin): + """Mixin to simplify usage of the `dsfr_breadcrumb` in class based views. + + Add the breadcrumb elements in the view context for the dsfr breadcrumb: + https://numerique-gouv.github.io/django-dsfr/components/breadcrumb/. + + ```python + breadcrumb_links = [{"url": "first-url", "title": "First title"}, {...}], + breadcrumb_current: "Current page title", + breadcrumb_root_dir: "the root directory, if the site is not installed at the + root of the domain" + } + ``` + """ + + breadcrumb_links: list[dict[StrOrPromise, StrOrPromise]] | None = None + breadcrumb_current: StrOrPromise | None = None + breadcrumb_root_dir: StrOrPromise | None = None + + def get_context_data(self, **kwargs) -> dict: + """Add breadcrumb context to the view.""" + context = super().get_context_data(**kwargs) + + context["breadcrumb_data"] = { + "links": self.breadcrumb_links, + "current": self.breadcrumb_current, + } + if self.breadcrumb_root_dir: + context["breadcrumb_data"]["root_dir"] = self.breadcrumb_root_dir + + return context diff --git a/src/dashboard/apps/consent/templates/consent/forms/widgets/checkbox.html b/src/dashboard/apps/consent/templates/consent/forms/widgets/checkbox.html new file mode 100644 index 00000000..519a6996 --- /dev/null +++ b/src/dashboard/apps/consent/templates/consent/forms/widgets/checkbox.html @@ -0,0 +1,7 @@ +{% include "django/forms/widgets/input.html" %} + + diff --git a/src/dashboard/apps/consent/templates/consent/manage.html b/src/dashboard/apps/consent/templates/consent/manage.html index aa5e17ad..029fa689 100644 --- a/src/dashboard/apps/consent/templates/consent/manage.html +++ b/src/dashboard/apps/consent/templates/consent/manage.html @@ -3,85 +3,87 @@ {% load i18n static %} {% block dashboard_content %} -