Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 malcolmt authored
7 django/newforms/widgets.py
View
@@ -161,8 +161,11 @@ def __init__(self, attrs=None, format=None):
self.format = format
def render(self, name, value, attrs=None):
- return super(DateTimeInput, self).render(name,
- value.strftime(self.format), attrs)
+ if value is None:
+ value = ''
+ elif hasattr(value, 'strftime'):
+ value = value.strftime(self.format)
+ return super(DateTimeInput, self).render(name, value, attrs)
class CheckboxInput(Widget):
def __init__(self, attrs=None, check_test=bool):
2  tests/regressiontests/forms/widgets.py
View
@@ -855,6 +855,8 @@
# DateTimeInput ###############################################################
>>> w = DateTimeInput()
+>>> w.render('date', None)
+u'<input type="text" name="date" />'
>>> d = datetime.datetime(2007, 9, 17, 12, 51, 34, 482548)
>>> print d
2007-09-17 12:51:34.482548
Please sign in to comment.
Something went wrong with that request. Please try again.