#35439: Hardcoded HTML in python code.
------------------------------------------------+------------------------
               Reporter:  sesostris             |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  contrib.admin         |        Version:  5.0
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 There is a hardcoded snippet of HTML in the
 django.contrib.admin.templatetags.admin_list module on lines 99 to 110
 that will be used in the header of the changelist results table.

 
https://github.com/django/django/blob/0e445badd54fafc75dd1a5dff9fee6e6a171eafe/django/contrib/admin/templatetags/admin_list.py#L99C1-L110C25

 {{{
             # if the field is the action checkbox: no sorting and special
 class
             if field_name == "action_checkbox":
                 aria_label = _("Select all objects on this page for an
 action")
                 yield {
                     "text": mark_safe(
                         f'<input type="checkbox" id="action-toggle" '
                         f'aria-label="{aria_label}">'
                     ),
                     "class_attrib": mark_safe(' class="action-checkbox-
 column"'),
                     "sortable": False,
                 }
                 continue
 }}}

 It would be better to use a CheckboxInput widget to render this HTML
 element. The code would look like this:

 {{{
 from django.forms import CheckboxInput

         # if the field is the action checkbox: no sorting and special
 class
         if field_name == "action_checkbox":
             widget = CheckboxInput(
                 attrs={
                     "aria-label": _(
                         "Select all objects on this page for an action"
                     ),
                     "id": "action-toggle",
                 }
             )
             yield {
                 "text": mark_safe(
                     widget.render(name="action-toggle", value=False)
                 ),
                 "class_attrib": mark_safe(' class="action-checkbox-
 column"'),
                 "sortable": False,
             }
             continue
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35439>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f58380532-5174af08-89f1-40b2-ad31-061c017a85a6-000000%40eu-central-1.amazonses.com.

Reply via email to