summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py5
-rw-r--r--django/forms/widgets.py12
2 files changed, 14 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 5537cf66f9..02c4c3db88 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -27,14 +27,14 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode, smart_str
from util import ErrorList, ValidationError
-from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput
+from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput, TimeInput
from django.core.files.uploadedfile import SimpleUploadedFile as UploadedFile
__all__ = (
'Field', 'CharField', 'IntegerField',
'DEFAULT_DATE_INPUT_FORMATS', 'DateField',
'DEFAULT_TIME_INPUT_FORMATS', 'TimeField',
- 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField',
+ 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField', 'TimeField',
'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField',
'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField',
'ComboField', 'MultiValueField', 'FloatField', 'DecimalField',
@@ -311,6 +311,7 @@ DEFAULT_TIME_INPUT_FORMATS = (
)
class TimeField(Field):
+ widget = TimeInput()
default_error_messages = {
'invalid': _(u'Enter a valid time.')
}
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)