Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14311 closed (wontfix)

Improve django.template.defaultfilters.title

Reported by: Mike Lissner Owned by: nobody
Component: Template system Version: 1.2
Severity: Keywords: sprintdec2010
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The title case function is a bit naively implemented, and could be vastly improved by pulling in some functionality from other titlecase tools.

Some things (I think) it doesn't cover:

  • small words shouldn't be capitalized (a, an, the, and, etc.), except when they are the first word in the string ("A Walk in the Park")
  • words like "Q&A" and "AT&T" should work
  • apostrophes: "AT&T's Network", "O'Donnell", "Don't"
  • hyphenated words: "Dangerously-Endowed"
  • Mc: "McDonald's"

It would also be great if it had a variable that could contain words that should be uppercase, such as:

There are some good reference implementations of this, but probably the best is this one:

Change History (4)

comment:1 Changed 8 years ago by Ramiro Morales

I'd suggest to implement it as a separate filter, maintain it as a third party project and/or propose it for inclusion in Django once all these enhancements prove to be useful to a sizable body of developers.

comment:2 Changed 8 years ago by Daniel F Moisset

Component: UncategorizedTemplate system

comment:3 Changed 8 years ago by Thomas Ashelford

Resolution: wontfix
Status: newclosed

Discussed this with Russell at the django sprint. Basically ramiro has hit the nail on the head. This is potentially a large and controversial problem space. It's probably best to let a solution float to the top rather than mandate some sort of canonical solution from within Django. At least the existing filter is simple, predictable, and easy to understand.

Maybe you could start the ball rolling by writing a simple django template filter wrapper around the library you reference and see if folks find it useful?

comment:4 Changed 8 years ago by Thomas Ashelford

Keywords: sprintdec2010 added
Note: See TracTickets for help on using tickets.
Back to Top