Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #9520: make the date filter fail silently for non-date …

…values. Thanks, Andrew Badr and Eric Holscher. Backport of r10365 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10366 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4257feffe8af5f31c0e851754db802ce7a8a0912 1 parent 38aeee4
Jacob Kaplan-Moss jacobian authored
10 django/template/defaultfilters.py
View
@@ -673,7 +673,10 @@ def date(value, arg=None):
return u''
if arg is None:
arg = settings.DATE_FORMAT
- return format(value, arg)
+ try:
+ return format(value, arg)
+ except AttributeError:
+ return ''
date.is_safe = False
def time(value, arg=None):
@@ -683,7 +686,10 @@ def time(value, arg=None):
return u''
if arg is None:
arg = settings.TIME_FORMAT
- return time_format(value, arg)
+ try:
+ return time_format(value, arg)
+ except AttributeError:
+ return ''
time.is_safe = False
def timesince(value, arg=None):
6 tests/regressiontests/templates/filters.py
View
@@ -317,4 +317,10 @@ def get_filter_tests():
'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'),
'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'}, ''),
}
Please sign in to comment.
Something went wrong with that request. Please try again.