Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 9828557731072ccc5734bed520d6efcde620dc1d 1 parent ef9bedf
Jacob Kaplan-Moss authored April 02, 2009
10  django/template/defaultfilters.py
@@ -681,7 +681,10 @@ def date(value, arg=None):
681 681
         return u''
682 682
     if arg is None:
683 683
         arg = settings.DATE_FORMAT
684  
-    return format(value, arg)
  684
+    try:
  685
+        return format(value, arg)
  686
+    except AttributeError:
  687
+        return ''
685 688
 date.is_safe = False
686 689
 
687 690
 def time(value, arg=None):
@@ -691,7 +694,10 @@ def time(value, arg=None):
691 694
         return u''
692 695
     if arg is None:
693 696
         arg = settings.TIME_FORMAT
694  
-    return time_format(value, arg)
  697
+    try:
  698
+        return time_format(value, arg)
  699
+    except AttributeError:
  700
+        return ''
695 701
 time.is_safe = False
696 702
 
697 703
 def timesince(value, arg=None):
6  tests/regressiontests/templates/filters.py
@@ -320,4 +320,10 @@ def get_filter_tests():
320 320
         'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'),
321 321
         'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
322 322
         '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'}, ''),
323 329
     }

0 notes on commit 9828557

Please sign in to comment.
Something went wrong with that request. Please try again.