Opened 14 years ago

Closed 14 years ago

Last modified 14 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

Description

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:
TITLE_BIG_WORDS = ("FBI", "CIA", "SEC", "EFF",)

There are some good reference implementations of this, but probably the best is this one: https://bugs.launchpad.net/titlecase.py

Change History (4)

comment:1 by Ramiro Morales, 14 years ago

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 by Daniel F Moisset, 14 years ago

Component: UncategorizedTemplate system

comment:3 by Thomas Ashelford, 14 years ago

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 by Thomas Ashelford, 14 years ago

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