Fixed #9520: make the date filter fail silently for non-date values. Thanks, Andrew Badr and Eric Holscher.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10365 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2009-04-02 05:20:25 +00:00
parent ef9bedf815
commit 9828557731
2 changed files with 14 additions and 2 deletions

View File

@ -681,7 +681,10 @@ def date(value, arg=None):
return u'' return u''
if arg is None: if arg is None:
arg = settings.DATE_FORMAT arg = settings.DATE_FORMAT
return format(value, arg) try:
return format(value, arg)
except AttributeError:
return ''
date.is_safe = False date.is_safe = False
def time(value, arg=None): def time(value, arg=None):
@ -691,7 +694,10 @@ def time(value, arg=None):
return u'' return u''
if arg is None: if arg is None:
arg = settings.TIME_FORMAT arg = settings.TIME_FORMAT
return time_format(value, arg) try:
return time_format(value, arg)
except AttributeError:
return ''
time.is_safe = False time.is_safe = False
def timesince(value, arg=None): def timesince(value, arg=None):

View File

@ -320,4 +320,10 @@ def get_filter_tests():
'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'), 'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'),
'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'), 'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'), 'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
'date01': (r'{{ d|date:"m" }}', {'d': datetime(2008, 1, 1)}, '01'),
'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'),
#Ticket 9520: Make sure |date doesn't blow up on non-dates
'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''),
} }