Opened 10 years ago
Closed 9 years ago
#24316 closed Bug (fixed)
Admin changelist column CSS classes do not use short description, instead using str(list_display_function)
Reported by: | JordanBright | Owned by: | |
---|---|---|---|
Component: | contrib.admin | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | francis@… | 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
The column names in a changelist respect the short description but the CSS classes do not. This is particularly bad if you use a lambda as the class name becomes column-< ;function <lambda> at ...
in the th
and field-<function <lambda> at ...
in the td
.
I think this is caused by two functions in django/contrib/admin/templatetags/admin_list.py
result_headers
uses field_name
from for i, field_name in enumerate(cl.list_display)
when it should be using text
(from text, attr = label_for_field(...)
) and doing something to make it a safe css class name, I think
items_for_result
also uses field_name
from for field_name in cl.list_display
and it should probably just use whatever result_headers
should be using.
To reproduce simply create a lambda function and put it in a list display then inspect the header and field classes in your browser. I'll attach a test case that reproduces it shortly.
Attachments (2)
Change History (10)
by , 10 years ago
Attachment: | 24316_test_case.diff added |
---|
comment:1 by , 10 years ago
Component: | Uncategorized → contrib.admin |
---|
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
by , 10 years ago
Attachment: | 24316_test_case_1.diff added |
---|
comment:5 by , 9 years ago
Has patch: | set |
---|
I didn't check if this patch fully resolves the ticket, but here's an initial pull request.
I came across this while debugging #23285. A test would occasionally fail because it was checking the ordering of strings like "2000" and "2008" in the response and sometimes they would appear elsewhere in the response such as <td class="field-<function callable_year at 0x7fe02000f230>">
.
comment:6 by , 9 years ago
I improved the patch to address both cases mention in the ticket description. I chose to use callable.__name__
instead of short_description
as I didn't see why the short_description
should be considered for a CSS class. In particular, I expect it would be more common to change the short_description
than the callable's name, and I think less the CSS class changes, the better. Let me know if I missed something.
comment:7 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
PR https://github.com/django/django/pull/5885 looks good to me.
New TestCase since previous one was passing 2 asserts that it shouldn't