diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-22 13:13:12 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-22 13:13:12 +0000 |
| commit | 003b3c1a17e2ae54fe24b7f534469f8b661e2727 (patch) | |
| tree | 69ae76ae68e3f45b37084de6722a494793e3bbd3 | |
| parent | dbd1cb9083db8a0206a4b951813f4c8291afa824 (diff) | |
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
| -rw-r--r-- | django/newforms/widgets.py | 7 | ||||
| -rw-r--r-- | tests/regressiontests/forms/widgets.py | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index c3e4b09d93..076845427d 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -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): diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py index 032f3cbb91..cb1d084631 100644 --- a/tests/regressiontests/forms/widgets.py +++ b/tests/regressiontests/forms/widgets.py @@ -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 |
