Ticket #9520: 9520-with-tests.diff

File 9520-with-tests.diff, 1.7 KB (added by Eric Holscher, 9 years ago)
  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index 673d044..7db6715 100644
    a b def date(value, arg=None): 
    681681        return u''
    682682    if arg is None:
    683683        arg = settings.DATE_FORMAT
    684     return format(value, arg)
     684    try:
     685        return format(value, arg)
     686    except AttributeError:
     687        return ''
    685688date.is_safe = False
    686689
    687690def time(value, arg=None):
    def time(value, arg=None): 
    691694        return u''
    692695    if arg is None:
    693696        arg = settings.TIME_FORMAT
    694     return time_format(value, arg)
     697    try:
     698        return time_format(value, arg)
     699    except AttributeError:
     700        return ''
    695701time.is_safe = False
    696702
    697703def timesince(value, arg=None):
  • tests/regressiontests/templates/filters.py

    diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
    index 91afdc7..e8b1dbe 100644
    a b def get_filter_tests(): 
    320320        'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'),
    321321        'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
    322322        'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
     323
     324
     325        'date01': (r'{{ d|date:"m" }}', {'d': datetime(2008, 1, 1)}, '01'),
     326        'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'),
     327        #Ticket 9520: Make sure |date doesn't blow up on non-dates
     328        'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''),
    323329    }
Back to Top