Ticket #7100: defaultfilters.diff

File defaultfilters.diff, 1.2 KB (added by dvainsencher, 17 years ago)
  • django/template/defaultfilters.py

     
    1010from django.template import Variable, Library
    1111from django.conf import settings
    1212from django.utils.translation import ugettext, ungettext
    13 from django.utils.encoding import force_unicode, iri_to_uri
     13from django.utils.encoding import force_unicode, iri_to_uri,smart_str
    1414from django.utils.safestring import mark_safe, SafeData
    1515
    1616register = Library()
     
    2828    def _dec(*args, **kwargs):
    2929        if args:
    3030            args = list(args)
     31            if getattr(func, 'to_str', False):
     32                args[0] = smart_str(args[0])
    3133            args[0] = force_unicode(args[0])
    3234            if isinstance(args[0], SafeData) and getattr(func, 'is_safe', False):
    3335                return mark_safe(func(*args, **kwargs))
     
    223225        return value # Fail silently.
    224226    return truncate_words(value, length)
    225227truncatewords.is_safe = True
     228truncatewords.to_str = True
    226229truncatewords = stringfilter(truncatewords)
    227230
    228231def truncatewords_html(value, arg):
Back to Top