Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14311 closed (wontfix)

Improve django.template.defaultfilters.title

Reported by: mlissner 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: UI/UX:

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 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 5 years ago by dmoisset

  • Component changed from Uncategorized to Template system

comment:3 Changed 5 years ago by tttallis

  • Resolution set to wontfix
  • Status changed from new to closed

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 5 years ago by tttallis

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