From d1216e126f21627db4302f0d2ded52e4c0386d3b Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Thu, 26 Aug 2021 17:43:40 +0200 Subject: [PATCH] Fixed #33051 -- Fixed highlighting the current model in admin's sidebar with non-ASCII model names. --- .../contrib/admin/templates/admin/app_list.html | 6 +++--- tests/admin_views/models.py | 4 ++++ tests/admin_views/test_nav_sidebar.py | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/django/contrib/admin/templates/admin/app_list.html b/django/contrib/admin/templates/admin/app_list.html index ea4a85bd0b..00c4178bd2 100644 --- a/django/contrib/admin/templates/admin/app_list.html +++ b/django/contrib/admin/templates/admin/app_list.html @@ -2,15 +2,15 @@ {% if app_list %} {% for app in app_list %} -
+
{% for model in app.models %} - + {% if model.admin_url %} - + {% else %} {% endif %} diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py index 36a8423c41..73459e2995 100644 --- a/tests/admin_views/models.py +++ b/tests/admin_views/models.py @@ -1046,3 +1046,7 @@ class ReadOnlyRelatedField(models.Model): chapter = models.ForeignKey(Chapter, models.CASCADE) language = models.ForeignKey(Language, models.CASCADE) user = models.ForeignKey(User, models.CASCADE) + + +class Héllo(models.Model): + pass diff --git a/tests/admin_views/test_nav_sidebar.py b/tests/admin_views/test_nav_sidebar.py index 04811489a7..c2e45d91a2 100644 --- a/tests/admin_views/test_nav_sidebar.py +++ b/tests/admin_views/test_nav_sidebar.py @@ -4,6 +4,8 @@ from django.contrib.auth.models import User from django.test import TestCase, override_settings from django.urls import path, reverse +from .models import Héllo + class AdminSiteWithSidebar(admin.AdminSite): pass @@ -17,6 +19,7 @@ site_with_sidebar = AdminSiteWithSidebar(name='test_with_sidebar') site_without_sidebar = AdminSiteWithoutSidebar(name='test_without_sidebar') site_with_sidebar.register(User) +site_with_sidebar.register(Héllo) urlpatterns = [ path('test_sidebar/admin/', site_with_sidebar.urls), @@ -85,9 +88,23 @@ class AdminSidebarTests(TestCase): with self.assertNoLogs('django.template', 'DEBUG'): self.client.get(url) + def test_sidebar_model_name_non_ascii(self): + url = reverse('test_with_sidebar:admin_views_héllo_changelist') + response = self.client.get(url) + self.assertContains(response, '
') + self.assertContains(response, '
') + self.assertContains( + response, + '' + ) + @override_settings(ROOT_URLCONF='admin_views.test_nav_sidebar') class SeleniumTests(AdminSeleniumTestCase): + available_apps = ['admin_views'] + AdminSeleniumTestCase.available_apps + def setUp(self): self.superuser = User.objects.create_superuser( username='super',
{{ app.name }}
{{ model.name }}{{ model.name }}{{ model.name }}
' + '' + 'Héllos