mirror of https://github.com/django/django.git
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:
parent
ef9bedf815
commit
9828557731
|
@ -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):
|
||||||
|
|
|
@ -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'}, ''),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue