mirror of
https://github.com/django/django.git
synced 2025-05-05 22:47:32 +00:00
Fixed #34909 -- Associated links in admin navigation sidebar with row descriptions.
This adds aria-describedby attribute to the models' links in the admin navigation sidebar. Thanks Thibaud Colas for the review. Co-authored-by: Dara Silvera <dsilvera@octobot.io>
This commit is contained in:
parent
5b885106a7
commit
c83c639ba0
@ -10,7 +10,7 @@
|
|||||||
{% for model in app.models %}
|
{% for model in app.models %}
|
||||||
{% with model_name=model.object_name|lower %}
|
{% with model_name=model.object_name|lower %}
|
||||||
<tr class="model-{{ model_name }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
|
<tr class="model-{{ model_name }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
|
||||||
<th scope="row">
|
<th scope="row" id="{{ app.app_label }}-{{ model_name }}">
|
||||||
{% if model.admin_url %}
|
{% if model.admin_url %}
|
||||||
<a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ model.name }}</a>
|
<a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ model.name }}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -19,16 +19,16 @@
|
|||||||
</th>
|
</th>
|
||||||
|
|
||||||
{% if model.add_url %}
|
{% if model.add_url %}
|
||||||
<td><a href="{{ model.add_url }}" class="addlink">{% translate 'Add' %}</a></td>
|
<td><a href="{{ model.add_url }}" class="addlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Add' %}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td></td>
|
<td></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if model.admin_url and show_changelinks %}
|
{% if model.admin_url and show_changelinks %}
|
||||||
{% if model.view_only %}
|
{% if model.view_only %}
|
||||||
<td><a href="{{ model.admin_url }}" class="viewlink">{% translate 'View' %}</a></td>
|
<td><a href="{{ model.admin_url }}" class="viewlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'View' %}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a href="{{ model.admin_url }}" class="changelink">{% translate 'Change' %}</a></td>
|
<td><a href="{{ model.admin_url }}" class="changelink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Change' %}</a></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif show_changelinks %}
|
{% elif show_changelinks %}
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -111,9 +111,10 @@ class AdminSidebarTests(TestCase):
|
|||||||
self.assertContains(response, '<tr class="model-héllo current-model">')
|
self.assertContains(response, '<tr class="model-héllo current-model">')
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'<th scope="row">'
|
'<th scope="row" id="admin_views-héllo">'
|
||||||
'<a href="/test_sidebar/admin/admin_views/h%C3%A9llo/" aria-current="page">'
|
'<a href="/test_sidebar/admin/admin_views/h%C3%A9llo/" aria-current="page">'
|
||||||
"Héllos</a></th>",
|
"Héllos</a></th>",
|
||||||
|
html=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1605,6 +1605,29 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||||||
'<main id="content-start" class="content" tabindex="-1">',
|
'<main id="content-start" class="content" tabindex="-1">',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_aria_describedby_for_add_and_change_links(self):
|
||||||
|
response = self.client.get(reverse("admin:index"))
|
||||||
|
tests = [
|
||||||
|
("admin_views", "actor"),
|
||||||
|
("admin_views", "worker"),
|
||||||
|
("auth", "group"),
|
||||||
|
("auth", "user"),
|
||||||
|
]
|
||||||
|
for app_label, model_name in tests:
|
||||||
|
with self.subTest(app_label=app_label, model_name=model_name):
|
||||||
|
row_id = f"{app_label}-{model_name}"
|
||||||
|
self.assertContains(response, f'<th scope="row" id="{row_id}">')
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
f'<a href="/test_admin/admin/{app_label}/{model_name}/" '
|
||||||
|
f'class="changelink" aria-describedby="{row_id}">Change</a>',
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
f'<a href="/test_admin/admin/{app_label}/{model_name}/add/" '
|
||||||
|
f'class="addlink" aria-describedby="{row_id}">Add</a>',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
AUTH_PASSWORD_VALIDATORS=[
|
AUTH_PASSWORD_VALIDATORS=[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user