#12434 closed (fixed)
django.contrib.admin does not work with blank short_description
Reported by: | anonymous | Owned by: | Gabriel Hurley |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ||
Cc: | ales.zoulek@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
After [11965] django.contrib.admin is broken for functions with blank short_description attribute.
I think the problem is with this function (django.contrib.forms.forms):
def pretty_name(name): "Converts 'first_name' to 'First name'" name = name[0].upper() + name[1:] return name.replace('_', ' ')
In django.contrib.admin.templatetags.admin_list, line 85, function label_for_field returns blank header for functions with blank short_description:
header = label_for_field(field_name, cl.model, cl.model_admin)
And line 91 use header as parameter for pretty_name:
header = pretty_name(header)
Attachments (3)
Change History (14)
comment:1 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
comment:3 by , 15 years ago
AFAIK capitalizce() doesn't work on non-ascii chars:
yed@deflorenc ~/skript/codegolf $ python Python 2.6.4 (r264:75706, Feb 2 2010, 11:10:56) [GCC 4.4.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print 'ř'.capitalize() ř
comment:4 by , 15 years ago
yedpodtrzitko: Yep, but neither does 'ř'.upper()
So no difference there...
comment:5 by , 15 years ago
Cc: | added |
---|
by , 15 years ago
Attachment: | pretty_name_complete.diff added |
---|
Patches pretty_name to use capitalize() and work with None and/or blank strings as argument.
comment:7 by , 15 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Capitalize works fine for international characters as long as the string is a unicode string:
>>> print u'ñ'.capitalize() Ñ
Even though it's probably overkill for a small patch, I ran some timeit tests to see how various solutions to this problem compared:
>>> import timeit >>> t1 = """\ ... name = u'el_ñino_season' ... name.capitalize().replace('_', ' ') ... """ >>> timeit.timeit(t1) 2.1008538794735085 >>> t2 = """\ ... name = u'el_ñino_season' ... name.upper().replace('_', ' ') ... """ >>> timeit.timeit(t2) 2.2086846233250319 >>> t3 = """\ ... name = u'el_ñino_season' ... name = name.upper() ... name.replace('_', ' ') ... """ >>> timeit.timeit(t3) 2.1825877311222515 >>> t4 = """\ ... name = u'el_ñino_season' ... if not name: ... return u'' ... name.replace('_', ' ').capitalize() ... """ >>> timeit.timeit(t4) 2.1088863905887484
My patch reflects option 4, which is consistently fast and handles the case of name being None.
comment:8 by , 15 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:10 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Is there a specific reason not to use .capitalize()