Opened 11 years ago

Closed 11 years ago

#21693 closed New feature (wontfix)

detaultfilter wordcap converts a string into titlecase but respect the actual uppercase

Reported by: Areski Belaid Owned by: nobody
Component: Template system Version: 1.6
Severity: Normal Keywords: filter
Cc: areski@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The defaultfilter title may in many cases be an issue to obtain a correct titlecase, for instance if the title contains acronyms or abbreviations. For instance, "SMS count"|title will display "Sms Count" which is not the desired result.

The defaultfilter wordcap try to provide a filter for this.
"SMS count"|wordcap -> "SMS Count"

Attachments (1)

patch_ticket_21693.txt (4.7 KB ) - added by Areski Belaid 11 years ago.

Download all attachments as: .zip

Change History (6)

by Areski Belaid, 11 years ago

Attachment: patch_ticket_21693.txt added

comment:1 by Areski Belaid, 11 years ago

Cc: areski@… added

comment:2 by Tim Graham, 11 years ago

I think this would be of enough general interest to include it with Django. The lower-casing behavior of the title filter has seemed funny to me. I've wanted to use something like it in the admin, but ended up having to use capfirst in its absence. The name also seems reasonable although I'd want to make sure no one can think of something better. I'll leave this ticket "unreviewed" for a second opinion. I see you've also submitted a pull request.

comment:3 by Baptiste Mispelon, 11 years ago

While I agree that the current implementation can be surprising when it comes to all-caps words, I would argue that:

1) It's basically a thin wrapper over Python's str.title [1] (with just a few extra special-casing for dealing with digits and apostrophes)
2) There's no such thing as "correct titlecase" since it depends on the locale (and even in English, there are different conventions)

So all-in-all, I'm personally -0 on the idea of adding a new add-hoc, English-centric template filter to the builtins.

[1] http://docs.python.org/3/library/stdtypes.html#str.title

comment:4 by Areski Belaid, 11 years ago

The main idea is to deal better with acronyms and abbreviation. This is also valid for many languages, it's not just English-centric, ie Spanish, French, Italian, Dutch, etc...

Yes, you are totally right, there is no such a thing as a correct titlecase.

I would agree for this not living in the core of Django, nevertheless I think this will be a good replacement where we use at the moment "title" in django-admin and for the beginners to try to deal easily with Abbreviation without creating a new templatetag.

comment:5 by Tim Graham, 11 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top