Ticket #11972: ticket_11972.diff

File ticket_11972.diff, 2.9 KB (added by Randy Barlow, 15 years ago)

Patch with unit test.

  • django/template/defaultfilters.py

     
    249249
    250250def title(value):
    251251    """Converts a string into titlecase."""
    252     return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
     252    t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
     253    return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)
    253254title.is_safe = True
    254255title = stringfilter(title)
    255256
  • tests/regressiontests/templates/filters.py

     
    120120
    121121        # Notice that escaping is applied *after* any filters, so the string
    122122        # formatting here only needs to deal with pre-escaped characters.
    123         'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}', {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
    124         'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, u".  a&lt;b. .  a<b."),
     123        'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}',
     124            {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
     125        'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")},
     126            u".  a&lt;b. .  a<b."),
    125127
    126         # XXX No test for "title" filter; needs an actual object.
     128        # Test the title filter
     129        'filter-title1' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, u'Joe&#39;s Crab Shack'),
     130        'filter-title2' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, u'555 West 53rd Street'),
    127131
    128         'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
    129         'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
     132        'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}',
     133            {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
     134        'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}',
     135            {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
    130136
    131137        # The "upper" filter messes up entities (which are case-sensitive),
    132138        # so it's not safe for non-escaping purposes.
Back to Top