mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Refs #31617 -- Added an id for helptext in admin forms.
This commit is contained in:
parent
50e1e7ef8e
commit
6991880109
@ -34,7 +34,7 @@
|
|||||||
{{ form.password1.errors }}
|
{{ form.password1.errors }}
|
||||||
{{ form.password1.label_tag }} {{ form.password1 }}
|
{{ form.password1.label_tag }} {{ form.password1 }}
|
||||||
{% if form.password1.help_text %}
|
{% if form.password1.help_text %}
|
||||||
<div class="help">{{ form.password1.help_text|safe }}</div>
|
<div class="help"{% if form.password1.id_for_label %} id="{{ form.password1.id_for_label }}_helptext">{% endif %}{{ form.password1.help_text|safe }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -42,7 +42,7 @@
|
|||||||
{{ form.password2.errors }}
|
{{ form.password2.errors }}
|
||||||
{{ form.password2.label_tag }} {{ form.password2 }}
|
{{ form.password2.label_tag }} {{ form.password2 }}
|
||||||
{% if form.password2.help_text %}
|
{% if form.password2.help_text %}
|
||||||
<div class="help">{{ form.password2.help_text|safe }}</div>
|
<div class="help"{% if form.password2.id_for_label %} id="{{ form.password2.id_for_label }}_helptext"{% endif %}>{{ form.password2.help_text|safe }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if field.field.help_text %}
|
{% if field.field.help_text %}
|
||||||
<div class="help">{{ field.field.help_text|safe }}</div>
|
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
|
||||||
|
{{ field.field.help_text|safe }}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<div id="toolbar"><form id="changelist-search" method="get">
|
<div id="toolbar"><form id="changelist-search" method="get">
|
||||||
<div><!-- DIV needed for valid HTML -->
|
<div><!-- DIV needed for valid HTML -->
|
||||||
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search"></label>
|
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search"></label>
|
||||||
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
|
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus{% if cl.search_help_text %} aria-describedby="searchbar_helptext"{% endif %}>
|
||||||
<input type="submit" value="{% translate 'Search' %}">
|
<input type="submit" value="{% translate 'Search' %}">
|
||||||
{% if show_result_count %}
|
{% if show_result_count %}
|
||||||
<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>
|
<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 @@
|
|||||||
</div>
|
</div>
|
||||||
{% if cl.search_help_text %}
|
{% if cl.search_help_text %}
|
||||||
<br class="clear">
|
<br class="clear">
|
||||||
<div class="help">{{ cl.search_help_text }}</div>
|
<div class="help" id="searchbar_helptext">{{ cl.search_help_text }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form></div>
|
</form></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
{{ form.new_password1.errors }}
|
{{ form.new_password1.errors }}
|
||||||
{{ form.new_password1.label_tag }} {{ form.new_password1 }}
|
{{ form.new_password1.label_tag }} {{ form.new_password1 }}
|
||||||
{% if form.new_password1.help_text %}
|
{% if form.new_password1.help_text %}
|
||||||
<div class="help">{{ form.new_password1.help_text|safe }}</div>
|
<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>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -47,7 +47,7 @@
|
|||||||
{{ form.new_password2.errors }}
|
{{ form.new_password2.errors }}
|
||||||
{{ form.new_password2.label_tag }} {{ form.new_password2 }}
|
{{ form.new_password2.label_tag }} {{ form.new_password2 }}
|
||||||
{% if form.new_password2.help_text %}
|
{% if form.new_password2.help_text %}
|
||||||
<div class="help">{{ form.new_password2.help_text|safe }}</div>
|
<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>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1523,7 +1523,7 @@ class ChangeListTests(TestCase):
|
|||||||
request = self._mocked_authenticated_request("/band/", superuser)
|
request = self._mocked_authenticated_request("/band/", superuser)
|
||||||
response = m.changelist_view(request)
|
response = m.changelist_view(request)
|
||||||
self.assertIsNone(response.context_data["cl"].search_help_text)
|
self.assertIsNone(response.context_data["cl"].search_help_text)
|
||||||
self.assertNotContains(response, '<div class="help">')
|
self.assertNotContains(response, '<div class="help id="searchbar_helptext">')
|
||||||
# search_fields with search_help_text.
|
# search_fields with search_help_text.
|
||||||
m.search_help_text = "Search help text"
|
m.search_help_text = "Search help text"
|
||||||
request = self._mocked_authenticated_request("/band/", superuser)
|
request = self._mocked_authenticated_request("/band/", superuser)
|
||||||
@ -1531,7 +1531,14 @@ class ChangeListTests(TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.context_data["cl"].search_help_text, "Search help text"
|
response.context_data["cl"].search_help_text, "Search help text"
|
||||||
)
|
)
|
||||||
self.assertContains(response, '<div class="help">Search help text</div>')
|
self.assertContains(
|
||||||
|
response, '<div class="help" id="searchbar_helptext">Search help text</div>'
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
'<input type="text" size="40" name="q" value="" id="searchbar" '
|
||||||
|
'autofocus aria-describedby="searchbar_helptext">',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GetAdminLogTests(TestCase):
|
class GetAdminLogTests(TestCase):
|
||||||
|
@ -263,9 +263,7 @@ class TestInline(TestDataMixin, TestCase):
|
|||||||
stacked and tabular layouts.
|
stacked and tabular layouts.
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse("admin:admin_inlines_holder4_add"))
|
response = self.client.get(reverse("admin:admin_inlines_holder4_add"))
|
||||||
self.assertContains(
|
self.assertContains(response, "Awesome stacked help text is awesome.", 4)
|
||||||
response, '<div class="help">Awesome stacked help text is awesome.</div>', 4
|
|
||||||
)
|
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'<img src="/static/admin/img/icon-unknown.svg" '
|
'<img src="/static/admin/img/icon-unknown.svg" '
|
||||||
|
@ -1449,8 +1449,43 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||||||
with self.assertNoLogs("django.template", "DEBUG"):
|
with self.assertNoLogs("django.template", "DEBUG"):
|
||||||
self.client.post(reverse("admin:admin_views_article_changelist"), post_data)
|
self.client.post(reverse("admin:admin_views_article_changelist"), post_data)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
AUTH_PASSWORD_VALIDATORS=[
|
||||||
|
{
|
||||||
|
"NAME": (
|
||||||
|
"django.contrib.auth.password_validation."
|
||||||
|
"UserAttributeSimilarityValidator"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"NAME": (
|
||||||
|
"django.contrib.auth.password_validation."
|
||||||
|
"NumericPasswordValidator"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_password_change_helptext(self):
|
||||||
|
response = self.client.get(reverse("admin:password_change"))
|
||||||
|
self.assertContains(
|
||||||
|
response, '<div class="help" id="id_new_password1_helptext">'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
|
AUTH_PASSWORD_VALIDATORS=[
|
||||||
|
{
|
||||||
|
"NAME": (
|
||||||
|
"django.contrib.auth.password_validation."
|
||||||
|
"UserAttributeSimilarityValidator"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"NAME": (
|
||||||
|
"django.contrib.auth.password_validation." "NumericPasswordValidator"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
],
|
||||||
TEMPLATES=[
|
TEMPLATES=[
|
||||||
{
|
{
|
||||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
@ -1470,7 +1505,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
class AdminCustomTemplateTests(AdminViewBasicTestCase):
|
class AdminCustomTemplateTests(AdminViewBasicTestCase):
|
||||||
def test_custom_model_admin_templates(self):
|
def test_custom_model_admin_templates(self):
|
||||||
@ -1563,6 +1598,19 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase):
|
|||||||
response, '<input type="text" name="username" value="super" class="hidden">'
|
response, '<input type="text" name="username" value="super" class="hidden">'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# help text for passwords has an id.
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
'<div class="help" id="id_password1_helptext"><ul><li>'
|
||||||
|
"Your password can’t be too similar to your other personal information."
|
||||||
|
"</li><li>Your password can’t be entirely numeric.</li></ul></div>",
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
'<div class="help" id="id_password2_helptext">'
|
||||||
|
"Enter the same password as before, for verification.</div>",
|
||||||
|
)
|
||||||
|
|
||||||
def test_extended_bodyclass_template_index(self):
|
def test_extended_bodyclass_template_index(self):
|
||||||
"""
|
"""
|
||||||
The admin/index.html template uses block.super in the bodyclass block.
|
The admin/index.html template uses block.super in the bodyclass block.
|
||||||
@ -6271,17 +6319,17 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
|
|||||||
self.assertContains(response, '<div class="form-row field-posted">')
|
self.assertContains(response, '<div class="form-row field-posted">')
|
||||||
self.assertContains(response, '<div class="form-row field-value">')
|
self.assertContains(response, '<div class="form-row field-value">')
|
||||||
self.assertContains(response, '<div class="form-row">')
|
self.assertContains(response, '<div class="form-row">')
|
||||||
self.assertContains(response, '<div class="help">', 3)
|
self.assertContains(response, '<div class="help"', 3)
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'<div class="help">Some help text for the title (with Unicode ŠĐĆŽćžšđ)'
|
'<div class="help" id="id_title_helptext">Some help text for the title '
|
||||||
"</div>",
|
"(with Unicode ŠĐĆŽćžšđ)</div>",
|
||||||
html=True,
|
html=True,
|
||||||
)
|
)
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'<div class="help">Some help text for the content (with Unicode ŠĐĆŽćžšđ)'
|
'<div class="help" id="id_content_helptext">Some help text for the content '
|
||||||
"</div>",
|
"(with Unicode ŠĐĆŽćžšđ)</div>",
|
||||||
html=True,
|
html=True,
|
||||||
)
|
)
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
@ -6468,7 +6516,9 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
|
|||||||
reverse("admin:admin_views_fieldoverridepost_change", args=(p.pk,))
|
reverse("admin:admin_views_fieldoverridepost_change", args=(p.pk,))
|
||||||
)
|
)
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response, '<div class="help">Overridden help text for the date</div>'
|
response,
|
||||||
|
'<div class="help">Overridden help text for the date</div>',
|
||||||
|
html=True,
|
||||||
)
|
)
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
|
Loading…
Reference in New Issue
Block a user