-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced function-based `consent_form_view` with `ConsentFormView` class-based view, leveraging Django forms for better structure and maintainability. Introduced a `ConsentForm` for managing consent input and added a `BreadcrumbContextMixin` to streamline breadcrumb handling. Updated templates and URLs accordingly for this refactor. Refactored consent views by splitting and improving helper functions for better clarity and reusability. Introduced comprehensive tests for `_bulk_update_consent`, ensuring proper validation of consent status updates with varied scenarios. This enhances maintainability and test coverage.
- Loading branch information
Showing
9 changed files
with
571 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."), | ||
}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
7 changes: 7 additions & 0 deletions
7
src/dashboard/apps/consent/templates/consent/forms/widgets/checkbox.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% include "django/forms/widgets/input.html" %} | ||
|
||
<label class="fr-label" | ||
{% if widget.attrs.id %}for="{{ widget.attrs.id }}"{% endif %}> | ||
{{ widget.attrs.label }} | ||
<span class="fr-hint-text">{{ widget.attrs.help_text }}</span> | ||
</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.