1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #35686 -- Added table headers to app list tables for screen readers.

This commit is contained in:
Sarah Boyce 2024-08-17 18:32:40 +02:00
parent 231c0d8593
commit d9ae7f5b58
3 changed files with 30 additions and 3 deletions

View File

@ -7,6 +7,13 @@
<caption> <caption>
<a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a> <a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a>
</caption> </caption>
<thead class="visually-hidden">
<tr>
<th scope="col">{% translate 'Model name' %}</th>
<th scope="col">{% translate 'Add link' %}</th>
<th scope="col">{% translate 'Change or view list link' %}</th>
</tr>
</thead>
{% 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 %}">

View File

@ -1608,7 +1608,7 @@ class ChangeListTests(TestCase):
response = m.changelist_view(request) response = m.changelist_view(request)
self.assertIn('<ul class="object-tools">', response.rendered_content) self.assertIn('<ul class="object-tools">', response.rendered_content)
# The "Add" button inside the object-tools shouldn't appear. # The "Add" button inside the object-tools shouldn't appear.
self.assertNotIn("Add ", response.rendered_content) self.assertNotIn("Add event", response.rendered_content)
def test_search_help_text(self): def test_search_help_text(self):
superuser = self._create_superuser("superuser") superuser = self._create_superuser("superuser")

View File

@ -799,7 +799,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
reverse("admin:admin_views_complexsortedperson_changelist"), {} reverse("admin:admin_views_complexsortedperson_changelist"), {}
) )
# Should have 5 columns (including action checkbox col) # Should have 5 columns (including action checkbox col)
self.assertContains(response, '<th scope="col"', count=5) result_list_table_re = re.compile('<table id="result_list">(.*?)</thead>')
result_list_table_head = result_list_table_re.search(str(response.content))[0]
self.assertEqual(result_list_table_head.count('<th scope="col"'), 5)
self.assertContains(response, "Name") self.assertContains(response, "Name")
self.assertContains(response, "Colored name") self.assertContains(response, "Colored name")
@ -830,7 +832,11 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
reverse("admin:admin_views_%s_changelist" % url), {} reverse("admin:admin_views_%s_changelist" % url), {}
) )
# Should have 3 columns including action checkbox col. # Should have 3 columns including action checkbox col.
self.assertContains(response, '<th scope="col"', count=3, msg_prefix=url) result_list_table_re = re.compile('<table id="result_list">(.*?)</thead>')
result_list_table_head = result_list_table_re.search(str(response.content))[
0
]
self.assertEqual(result_list_table_head.count('<th scope="col"'), 3)
# Check if the correct column was selected. 2 is the index of the # Check if the correct column was selected. 2 is the index of the
# 'order' column in the model admin's 'list_display' with 0 being # 'order' column in the model admin's 'list_display' with 0 being
# the implicit 'action_checkbox' and 1 being the column 'stuff'. # the implicit 'action_checkbox' and 1 being the column 'stuff'.
@ -7498,12 +7504,26 @@ class CSSTest(TestCase):
# General index page # General index page
response = self.client.get(reverse("admin:index")) response = self.client.get(reverse("admin:index"))
self.assertContains(response, '<div class="app-admin_views module') self.assertContains(response, '<div class="app-admin_views module')
self.assertContains(
response,
'<thead class="visually-hidden"><tr><th scope="col">Model name</th>'
'<th scope="col">Add link</th><th scope="col">Change or view list link</th>'
"</tr></thead>",
html=True,
)
self.assertContains(response, '<tr class="model-actor">') self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">') self.assertContains(response, '<tr class="model-album">')
# App index page # App index page
response = self.client.get(reverse("admin:app_list", args=("admin_views",))) response = self.client.get(reverse("admin:app_list", args=("admin_views",)))
self.assertContains(response, '<div class="app-admin_views module') self.assertContains(response, '<div class="app-admin_views module')
self.assertContains(
response,
'<thead class="visually-hidden"><tr><th scope="col">Model name</th>'
'<th scope="col">Add link</th><th scope="col">Change or view list link</th>'
"</tr></thead>",
html=True,
)
self.assertContains(response, '<tr class="model-actor">') self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">') self.assertContains(response, '<tr class="model-album">')