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:
parent
dbd1cb9083
commit
003b3c1a17
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue