summaryrefslogtreecommitdiff
path: root/django/forms/widgets.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-23 17:33:09 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-23 17:33:09 +0000
commit8a3ef1f8bce338b2ca255177b4ba6d020fd05bca (patch)
tree665cae0b70f0fea5f04c48eca5a8088d4065aa4c /django/forms/widgets.py
parent646f2f6101cda3e20908928de44739dfff596b0f (diff)
Fixed #7499 -- Trim microseconds off rendering of form.TimeFields by default so
that they validate. Previous code didn't work with microseconds anyway, so this is backwards compatible. Thanks to kevin for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8491 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 4dd0601d69..0d6c5bcbbc 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -22,7 +22,7 @@ from urlparse import urljoin
__all__ = (
'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'PasswordInput',
'HiddenInput', 'MultipleHiddenInput',
- 'FileInput', 'DateTimeInput', 'Textarea', 'CheckboxInput',
+ 'FileInput', 'DateTimeInput', 'TimeInput', 'Textarea', 'CheckboxInput',
'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect',
'CheckboxSelectMultiple', 'MultiWidget', 'SplitDateTimeWidget',
)
@@ -301,6 +301,16 @@ class DateTimeInput(Input):
value = value.strftime(self.format)
return super(DateTimeInput, self).render(name, value, attrs)
+class TimeInput(Input):
+ input_type = 'text'
+
+ def render(self, name, value, attrs=None):
+ if value is None:
+ value = ''
+ elif hasattr(value, 'replace'):
+ value = value.replace(microsecond=0)
+ return super(TimeInput, self).render(name, value, attrs)
+
class CheckboxInput(Widget):
def __init__(self, attrs=None, check_test=bool):
super(CheckboxInput, self).__init__(attrs)