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...
1 parent dbd1cb9 commit 003b3c1a17e2ae54fe24b7f534469f8b661e2727 @malcolmt malcolmt committed Oct 22, 2007
Showing with 7 additions and 2 deletions.
  1. +5 −2 django/newforms/widgets.py
  2. +2 −0 tests/regressiontests/forms/widgets.py
View
7 django/newforms/widgets.py
@@ -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):
View
2 tests/regressiontests/forms/widgets.py
@@ -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

0 comments on commit 003b3c1

Please sign in to comment.