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
This commit is contained in:
Malcolm Tredinnick 2007-10-22 13:13:12 +00:00
parent dbd1cb9083
commit 003b3c1a17
2 changed files with 7 additions and 2 deletions

View File

@ -161,8 +161,11 @@ class DateTimeInput(Input):
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 File

@ -855,6 +855,8 @@ u'<input type="text" class="pretty" value="2006-01-10" name="date_0" /><input ty
# 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