Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5794 -- Be more robust when rendering a DateTimeInput widget. …

…Thanks,

MikeH.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6594 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 003b3c1a17e2ae54fe24b7f534469f8b661e2727 1 parent dbd1cb9
Malcolm Tredinnick authored
7  django/newforms/widgets.py
@@ -161,8 +161,11 @@ def __init__(self, attrs=None, format=None):
161 161
             self.format = format
162 162
 
163 163
     def render(self, name, value, attrs=None):
164  
-        return super(DateTimeInput, self).render(name,
165  
-                value.strftime(self.format), attrs)
  164
+        if value is None:
  165
+            value = ''
  166
+        elif hasattr(value, 'strftime'):
  167
+            value = value.strftime(self.format)
  168
+        return super(DateTimeInput, self).render(name, value, attrs)
166 169
 
167 170
 class CheckboxInput(Widget):
168 171
     def __init__(self, attrs=None, check_test=bool):
2  tests/regressiontests/forms/widgets.py
@@ -855,6 +855,8 @@
855 855
 # DateTimeInput ###############################################################
856 856
 
857 857
 >>> w = DateTimeInput()
  858
+>>> w.render('date', None)
  859
+u'<input type="text" name="date" />'
858 860
 >>> d = datetime.datetime(2007, 9, 17, 12, 51, 34, 482548)
859 861
 >>> print d
860 862
 2007-09-17 12:51:34.482548

0 notes on commit 003b3c1

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