Projet

Général

Profil

0001-widgets-add-custom-widget-for-title-attribute-kind-5.patch

Serghei Mihai, 08 juin 2021 11:40

Télécharger (2,94 ko)

Voir les différences:

Subject: [PATCH] widgets: add custom widget for 'title' attribute kind
 (#54642)

 src/authentic2/attribute_kinds.py                      | 2 +-
 src/authentic2/forms/widgets.py                        | 4 ++++
 src/authentic2/templates/authentic2/widgets/title.html | 3 +++
 tests/test_widgets.py                                  | 8 +++++++-
 4 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 src/authentic2/templates/authentic2/widgets/title.html
src/authentic2/attribute_kinds.py
271 271
        'field_class': forms.ChoiceField,
272 272
        'kwargs': {
273 273
            'choices': get_title_choices(),
274
            'widget': forms.RadioSelect,
274
            'widget': widgets.TitleWidget,
275 275
        },
276 276
    },
277 277
    {
src/authentic2/forms/widgets.py
361 361
            )
362 362
            context['domains_suggested'] = True
363 363
        return context
364

  
365

  
366
class TitleWidget(forms.RadioSelect):
367
    template_name = 'authentic2/widgets/title.html'
src/authentic2/templates/authentic2/widgets/title.html
1
{% with id=widget.attrs.id %}<ul{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %} aria-labelledby="{{ id }}_0" role="radiogroup">{% for group, options, index in widget.optgroups %}{% for option in options %}
2
    <li>{% include option.template_name with widget=option %}</li>{% endfor %}{% endfor %}
3
</ul>{% endwith %}
tests/test_widgets.py
17 17

  
18 18
from pyquery import PyQuery
19 19

  
20
from authentic2.widgets import DatalistTextInput, DateTimeWidget, DateWidget, TimeWidget
20
from authentic2.widgets import DatalistTextInput, DateTimeWidget, DateWidget, TimeWidget, TitleWidget
21 21

  
22 22

  
23 23
def test_datetimepicker_init_and_render_no_locale():
......
50 50
        assert option.values()[0] in data
51 51
        data.remove(option.values()[0])
52 52
    assert not data
53

  
54

  
55
def test_title_render():
56
    html = TitleWidget(choices=[('m', 'M'), ('f', 'F')]).render('title', '', attrs={'id': 'title'})
57
    assert 'role="radiogroup"' in html
58
    assert 'aria-labelledby="title_0"' in html
53
-