Skip to content

Commit 6991880

Browse files
smithdc1carltongibson
authored andcommitted
Refs #31617 -- Added an id for helptext in admin forms.
1 parent 50e1e7e commit 6991880

File tree

7 files changed

+76
-19
lines changed

7 files changed

+76
-19
lines changed

django/contrib/admin/templates/admin/auth/user/change_password.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
{{ form.password1.errors }}
3535
{{ form.password1.label_tag }} {{ form.password1 }}
3636
{% if form.password1.help_text %}
37-
<div class="help">{{ form.password1.help_text|safe }}</div>
37+
<div class="help"{% if form.password1.id_for_label %} id="{{ form.password1.id_for_label }}_helptext">{% endif %}{{ form.password1.help_text|safe }}</div>
3838
{% endif %}
3939
</div>
4040

4141
<div class="form-row">
4242
{{ form.password2.errors }}
4343
{{ form.password2.label_tag }} {{ form.password2 }}
4444
{% if form.password2.help_text %}
45-
<div class="help">{{ form.password2.help_text|safe }}</div>
45+
<div class="help"{% if form.password2.id_for_label %} id="{{ form.password2.id_for_label }}_helptext"{% endif %}>{{ form.password2.help_text|safe }}</div>
4646
{% endif %}
4747
</div>
4848

django/contrib/admin/templates/admin/includes/fieldset.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
{% endif %}
2121
{% endif %}
2222
{% if field.field.help_text %}
23-
<div class="help">{{ field.field.help_text|safe }}</div>
23+
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
24+
{{ field.field.help_text|safe }}
25+
</div>
2426
{% endif %}
2527
</div>
2628
{% endfor %}

django/contrib/admin/templates/admin/search_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div id="toolbar"><form id="changelist-search" method="get">
44
<div><!-- DIV needed for valid HTML -->
55
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search"></label>
6-
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
6+
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus{% if cl.search_help_text %} aria-describedby="searchbar_helptext"{% endif %}>
77
<input type="submit" value="{% translate 'Search' %}">
88
{% if show_result_count %}
99
<span class="small quiet">{% blocktranslate count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktranslate %} (<a href="?{% if cl.is_popup %}{{ is_popup_var }}=1{% endif %}">{% if cl.show_full_result_count %}{% blocktranslate with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktranslate %}{% else %}{% translate "Show all" %}{% endif %}</a>)</span>
@@ -14,7 +14,7 @@
1414
</div>
1515
{% if cl.search_help_text %}
1616
<br class="clear">
17-
<div class="help">{{ cl.search_help_text }}</div>
17+
<div class="help" id="searchbar_helptext">{{ cl.search_help_text }}</div>
1818
{% endif %}
1919
</form></div>
2020
{% endif %}

django/contrib/admin/templates/registration/password_change_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
{{ form.new_password1.errors }}
4040
{{ form.new_password1.label_tag }} {{ form.new_password1 }}
4141
{% if form.new_password1.help_text %}
42-
<div class="help">{{ form.new_password1.help_text|safe }}</div>
42+
<div class="help"{% if form.new_password1.id_for_label %} id="{{ form.new_password1.id_for_label }}_helptext"{% endif %}>{{ form.new_password1.help_text|safe }}</div>
4343
{% endif %}
4444
</div>
4545

4646
<div class="form-row">
4747
{{ form.new_password2.errors }}
4848
{{ form.new_password2.label_tag }} {{ form.new_password2 }}
4949
{% if form.new_password2.help_text %}
50-
<div class="help">{{ form.new_password2.help_text|safe }}</div>
50+
<div class="help"{% if form.new_password2.id_for_label %} id="{{ form.new_password2.id_for_label }}_helptext"{% endif %}>{{ form.new_password2.help_text|safe }}</div>
5151
{% endif %}
5252
</div>
5353

tests/admin_changelist/tests.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,15 +1523,22 @@ def test_search_help_text(self):
15231523
request = self._mocked_authenticated_request("/band/", superuser)
15241524
response = m.changelist_view(request)
15251525
self.assertIsNone(response.context_data["cl"].search_help_text)
1526-
self.assertNotContains(response, '<div class="help">')
1526+
self.assertNotContains(response, '<div class="help id="searchbar_helptext">')
15271527
# search_fields with search_help_text.
15281528
m.search_help_text = "Search help text"
15291529
request = self._mocked_authenticated_request("/band/", superuser)
15301530
response = m.changelist_view(request)
15311531
self.assertEqual(
15321532
response.context_data["cl"].search_help_text, "Search help text"
15331533
)
1534-
self.assertContains(response, '<div class="help">Search help text</div>')
1534+
self.assertContains(
1535+
response, '<div class="help" id="searchbar_helptext">Search help text</div>'
1536+
)
1537+
self.assertContains(
1538+
response,
1539+
'<input type="text" size="40" name="q" value="" id="searchbar" '
1540+
'autofocus aria-describedby="searchbar_helptext">',
1541+
)
15351542

15361543

15371544
class GetAdminLogTests(TestCase):

tests/admin_inlines/tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ def test_help_text(self):
263263
stacked and tabular layouts.
264264
"""
265265
response = self.client.get(reverse("admin:admin_inlines_holder4_add"))
266-
self.assertContains(
267-
response, '<div class="help">Awesome stacked help text is awesome.</div>', 4
268-
)
266+
self.assertContains(response, "Awesome stacked help text is awesome.", 4)
269267
self.assertContains(
270268
response,
271269
'<img src="/static/admin/img/icon-unknown.svg" '

tests/admin_views/tests.py

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,43 @@ def test_render_delete_selected_confirmation_no_subtitle(self):
14491449
with self.assertNoLogs("django.template", "DEBUG"):
14501450
self.client.post(reverse("admin:admin_views_article_changelist"), post_data)
14511451

1452+
@override_settings(
1453+
AUTH_PASSWORD_VALIDATORS=[
1454+
{
1455+
"NAME": (
1456+
"django.contrib.auth.password_validation."
1457+
"UserAttributeSimilarityValidator"
1458+
)
1459+
},
1460+
{
1461+
"NAME": (
1462+
"django.contrib.auth.password_validation."
1463+
"NumericPasswordValidator"
1464+
)
1465+
},
1466+
]
1467+
)
1468+
def test_password_change_helptext(self):
1469+
response = self.client.get(reverse("admin:password_change"))
1470+
self.assertContains(
1471+
response, '<div class="help" id="id_new_password1_helptext">'
1472+
)
1473+
14521474

14531475
@override_settings(
1476+
AUTH_PASSWORD_VALIDATORS=[
1477+
{
1478+
"NAME": (
1479+
"django.contrib.auth.password_validation."
1480+
"UserAttributeSimilarityValidator"
1481+
)
1482+
},
1483+
{
1484+
"NAME": (
1485+
"django.contrib.auth.password_validation." "NumericPasswordValidator"
1486+
)
1487+
},
1488+
],
14541489
TEMPLATES=[
14551490
{
14561491
"BACKEND": "django.template.backends.django.DjangoTemplates",
@@ -1470,7 +1505,7 @@ def test_render_delete_selected_confirmation_no_subtitle(self):
14701505
],
14711506
},
14721507
}
1473-
]
1508+
],
14741509
)
14751510
class AdminCustomTemplateTests(AdminViewBasicTestCase):
14761511
def test_custom_model_admin_templates(self):
@@ -1563,6 +1598,19 @@ def test_change_password_template(self):
15631598
response, '<input type="text" name="username" value="super" class="hidden">'
15641599
)
15651600

1601+
# help text for passwords has an id.
1602+
self.assertContains(
1603+
response,
1604+
'<div class="help" id="id_password1_helptext"><ul><li>'
1605+
"Your password can’t be too similar to your other personal information."
1606+
"</li><li>Your password can’t be entirely numeric.</li></ul></div>",
1607+
)
1608+
self.assertContains(
1609+
response,
1610+
'<div class="help" id="id_password2_helptext">'
1611+
"Enter the same password as before, for verification.</div>",
1612+
)
1613+
15661614
def test_extended_bodyclass_template_index(self):
15671615
"""
15681616
The admin/index.html template uses block.super in the bodyclass block.
@@ -6271,17 +6319,17 @@ def test_readonly_get(self):
62716319
self.assertContains(response, '<div class="form-row field-posted">')
62726320
self.assertContains(response, '<div class="form-row field-value">')
62736321
self.assertContains(response, '<div class="form-row">')
6274-
self.assertContains(response, '<div class="help">', 3)
6322+
self.assertContains(response, '<div class="help"', 3)
62756323
self.assertContains(
62766324
response,
6277-
'<div class="help">Some help text for the title (with Unicode ŠĐĆŽćžšđ)'
6278-
"</div>",
6325+
'<div class="help" id="id_title_helptext">Some help text for the title '
6326+
"(with Unicode ŠĐĆŽćžšđ)</div>",
62796327
html=True,
62806328
)
62816329
self.assertContains(
62826330
response,
6283-
'<div class="help">Some help text for the content (with Unicode ŠĐĆŽćžšđ)'
6284-
"</div>",
6331+
'<div class="help" id="id_content_helptext">Some help text for the content '
6332+
"(with Unicode ŠĐĆŽćžšđ)</div>",
62856333
html=True,
62866334
)
62876335
self.assertContains(
@@ -6468,7 +6516,9 @@ def test_readonly_field_overrides(self):
64686516
reverse("admin:admin_views_fieldoverridepost_change", args=(p.pk,))
64696517
)
64706518
self.assertContains(
6471-
response, '<div class="help">Overridden help text for the date</div>'
6519+
response,
6520+
'<div class="help">Overridden help text for the date</div>',
6521+
html=True,
64726522
)
64736523
self.assertContains(
64746524
response,

0 commit comments

Comments
 (0)