Opened 4 years ago
Closed 4 years ago
#33051 closed Bug (fixed)
Model names with special characters don't highlight in admin site
| Reported by: | ꯸ ꬰ ꝛ⼻ↇ | Owned by: | Hasan Ramezani |
|---|---|---|---|
| Component: | contrib.admin | Version: | 3.2 |
| Severity: | Normal | Keywords: | accents, unicode |
| Cc: | Tom Carrick, Matthias Kestenholz | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Create two models, one without special characters Hello and another with Héllo, register both with the admin website.
Then, when you click on Hello in the admin website it highlights in yellow in the sidebar, but it is not the case for Héllo, which remains white/gray. This is true for any number of models in any order, only those with an accent will exhibit this behaviour.
Change History (6)
comment:1 by , 4 years ago
| Cc: | added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 4 years ago
I have never used model names with umlauts or accents; I knew that Python 3 supports using unicode codepoints in class names too but I've never had a reason for using anything but [A-Za-z0-9_] when naming Django model classes (or any Python identifiers, for that matter)
I don't know that area of the Django admin very well but the fix looks correct to me. At least if Django even wants to support umlauts/accents in model names (and therefore also database table names, maybe?) at all.
request.path only exists in the admin/app_list.html template in django/contrib/admin/templates/ so I'd assume that the proposed patch fixes this problem.
TLDR: LGTM but I wouldn't ever use accents or umlauts in class names.
comment:5 by , 4 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Thanks for the report! Adding
urlencodefixes this issue for me:diff --git a/django/contrib/admin/templates/admin/app_list.html b/django/contrib/admin/templates/admin/app_list.html index ea4a85bd0b..e7517ea698 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 %} - <div class="app-{{ app.app_label }} module{% if app.app_url in request.path %} current-app{% endif %}"> + <div class="app-{{ app.app_label }} module{% if app.app_url in request.path|urlencode %} current-app{% endif %}"> <table> <caption> <a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a> </caption> {% for model in app.models %} - <tr class="model-{{ model.object_name|lower }}{% if model.admin_url in request.path %} current-model{% endif %}"> + <tr class="model-{{ model.object_name|lower }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}"> {% if model.admin_url %} - <th scope="row"><a href="{{ model.admin_url }}"{% if model.admin_url in request.path %} aria-current="page"{% endif %}>{{ model.name }}</a></th> + <th scope="row"><a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ model.name }}</a></th> {% else %} <th scope="row">{{ model.name }}</th> {% endif %}