Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehenry committed Sep 18, 2024
1 parent 6587d89 commit 36e925a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
27 changes: 13 additions & 14 deletions dsfr/templates/dsfr/widgets/rich_radio.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{% with id=widget.attrs.id %}
<fieldset
{% if id %}id="{{ id }}"{% endif %}
class="fr-fieldset{% if widget.attrs.class %} {{ widget.attrs.class }}{% endif %}"
{% if id %}aria-labelledby="{{ id }}-legend"{% endif %}
>
<fieldset {% if id %}id="{{ id }}"{% endif %}
class="fr-fieldset{% if widget.attrs.class %} {{ widget.attrs.class }}{% endif %}"
{% if id %}aria-labelledby="{{ id }}-legend"{% endif %}>
{% for group, options, index in widget.optgroups %}
{% if group %}
<legend
id="{{ group }}-legend"
class="fr-fieldset__legend{% if widget.attrs.legend_classes %} {{ widget.attrs.legend_classes }}{% endif %}"
>
<legend id="{{ group }}-legend"
class="fr-fieldset__legend{% if widget.attrs.legend_classes %} {{ widget.attrs.legend_classes }}{% endif %}">
{{ group }}
</legend>
<fieldset aria-labelledby="{{ group }}-legend">
{% endif %}
{% for option in options %}
{% include option.template_name with widget=option %}
{% endfor %}
{% if group %}
</fieldset>
{% endif %}
{% for option in options %}
{% include option.template_name with widget=option %}
{% endfor %}
{% if group %}</fieldset>{% endif %}
{% endfor %}
</fieldset>{% endwith %}
</fieldset>
{% endwith %}
17 changes: 10 additions & 7 deletions dsfr/templates/dsfr/widgets/rich_radio_option.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<div class="fr-fieldset__element{% if widget.inline %} fr-fieldset__element--inline{% endif %}">
<div class="fr-radio-group fr-radio-rich">
<input value="{{ widget.value }}" type="{{ widget.type }}" id="{{ widget.attrs.id }}" name="{{ widget.name }}">
<label class="fr-label" for="{{ widget.attrs.id }}">{{ widget.html_label }}</label>
<input value="{{ widget.value }}"
type="{{ widget.type }}"
id="{{ widget.attrs.id }}"
name="{{ widget.name }}">
<label class="fr-label" for="{{ widget.attrs.id }}">
{{ widget.html_label }}
</label>
{% if widget.pictogram %}
<div class="fr-radio-rich__pictogram">
<img
src="{{ widget.pictogram }}"
{% if widget.pictogram_alt is not None %} alt="{{ widget.pictogram_alt }}"{% endif %}
/>
<img src="{{ widget.pictogram }}"
{% if widget.pictogram_alt is not None %} alt="{{ widget.pictogram_alt }}"{% endif %} />
</div>
{% endif %}
</div>
</div>
</div>
18 changes: 13 additions & 5 deletions dsfr/test/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ class TestExtendedChoices(ExtendedChoices, IntegerChoices):
TEST_1 = {
"value": auto(),
"additionnal_attribute_1": {"lorem": "ipsum 1"},
"additionnal_attribute_2": mark_safe("<strong>Item 1</strong>"),
"additionnal_attribute_2": mark_safe(
"<strong>Item 1</strong>"
), # nosec
}
TEST_2 = {
"value": auto(),
"additionnal_attribute_1": {"lorem": "ipsum 2"},
"additionnal_attribute_2": mark_safe("<strong>Item 2</strong>"),
"additionnal_attribute_2": mark_safe(
"<strong>Item 2</strong>"
), # nosec
}

self.assertEqual(
Expand Down Expand Up @@ -149,12 +153,16 @@ class TestExtendedChoices(ExtendedChoices, IntegerChoices):
TEST_1 = {
"value": auto(),
"additionnal_attribute_1": {"lorem": "ipsum 1"},
"additionnal_attribute_2": mark_safe("<strong>Item 1</strong>"),
"additionnal_attribute_2": mark_safe(
"<strong>Item 1</strong>"
), # nosec
}
TEST_2 = {
"value": auto(),
"additionnal_attribute_1": {"lorem": "ipsum 2"},
"additionnal_attribute_2": mark_safe("<strong>Item 2</strong>"),
"additionnal_attribute_2": mark_safe(
"<strong>Item 2</strong>"
), # nosec
}

@staticmethod
Expand All @@ -164,4 +172,4 @@ def private_variable_name(name):
self.assertEqual(
{"<strong>Item 1</strong>", "<strong>Item 2</strong>"},
{it.m_additionnal_attribute_2 for it in TestExtendedChoices},
)
)
2 changes: 1 addition & 1 deletion dsfr/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Type

from django.forms.widgets import RadioSelect, ChoiceWidget, CheckboxSelectMultiple
from django.forms.widgets import RadioSelect, ChoiceWidget

from dsfr.enums import RichRadioButtonChoices

Expand Down
5 changes: 1 addition & 4 deletions example_app/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import functools
from enum import auto, FlagBoundary
from enum import auto

from django import forms
from django.db.models import TextChoices
from django.forms import (
ModelForm,
inlineformset_factory,
) # /!\ In order to use formsets
from django.templatetags.static import static
from django.db.models import IntegerChoices

from django.utils.functional import keep_lazy_text

from dsfr.constants import COLOR_CHOICES, COLOR_CHOICES_ILLUSTRATION
from dsfr.enums import RichRadioButtonChoices
Expand Down

0 comments on commit 36e925a

Please sign in to comment.