#35439: Hardcoded HTML in python code.
-------------------------------------+-------------------------------------
Reporter: sesostris | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):
I would also like to read the answer to the last question (''why using a
widget and rending the HTML using the template engine would be better'')
but is worth nothing that the following diff has the test passing OK so at
a code level it seems equivalent:
{{{#!diff
diff --git a/django/contrib/admin/templatetags/admin_list.py
b/django/contrib/admin/templatetags/admin_list.py
index fdf6e63f5f..e7b4fcb81f 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -1,5 +1,6 @@
import datetime
+from django.forms import CheckboxInput
from django.contrib.admin.templatetags.admin_urls import
add_preserved_filters
from django.contrib.admin.utils import (
display_for_field,
@@ -99,10 +100,15 @@ def result_headers(cl):
# 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")
+ widget = CheckboxInput(
+ attrs={
+ "aria-label": aria_label,
+ "id": "action-toggle",
+ }
+ )
yield {
"text": mark_safe(
- f'<input type="checkbox" id="action-toggle" '
- f'aria-label="{aria_label}">'
+ widget.render(name="action-toggle", value=False)
),
"class_attrib": mark_safe(' class="action-checkbox-
column"'),
"sortable": False,
diff --git a/tests/admin_changelist/tests.py
b/tests/admin_changelist/tests.py
index bf85cf038f..bf6245ca1f 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -359,7 +359,7 @@ class ChangeListTests(TestCase):
"Failed to find expected row element: %s" % table_output,
)
self.assertInHTML(
- '<input type="checkbox" id="action-toggle" '
+ '<input type="checkbox" id="action-toggle" name="action-
toggle"'
'aria-label="Select all objects on this page for an
action">',
table_output,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35439#comment:2>
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/0107018f5ed1d840-d8232777-0714-4c94-8ba8-51e869daf659-000000%40eu-central-1.amazonses.com.