Ticket #9483: patch_2_1.0.X.diff

File patch_2_1.0.X.diff, 2.4 KB (added by Henk de Vries, 15 years ago)

New patch with string.capwords(value) against 1.0.X.

  • django/template/defaultfilters.py

     
    11"""Default variable filters."""
    22
    33import re
     4import string
    45
    56try:
    67    from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
     
    245246
    246247def title(value):
    247248    """Converts a string into titlecase."""
    248     return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
     249    return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), string.capwords(value))
    249250title.is_safe = True
    250251title = stringfilter(title)
    251252
  • tests/regressiontests/defaultfilters/tests.py

     
    113113>>> title(u'discoth\xe8que')
    114114u'Discoth\xe8que'
    115115
     116>>> title('fun&niest li"ne ever')
     117u'Fun&niest Li"ne Ever'
     118
    116119>>> truncatewords(u'A sentence with a few words in it', 1)
    117120u'A ...'
    118121
  • tests/regressiontests/templates/filters.py

     
    113113        'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}', {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
    114114        'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, u".  a&lt;b. .  a<b."),
    115115
    116         # XXX No test for "title" filter; needs an actual object.
     116        # Check if "title" filter doesn't trip over quotes or ampersands
     117        'filter-title01': ('{{ a|title }}', {"a": "fun&niest li\"ne ever"}, "Fun&amp;niest Li&quot;ne Ever"),
    117118
    118119        'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
    119120        'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
Back to Top