Ticket #7499: time_input_widget.2.diff
File time_input_widget.2.diff, 3.5 KB (added by , 16 years ago) |
---|
-
django/forms/fields.py
27 27 from django.utils.encoding import smart_unicode, smart_str 28 28 29 29 from util import ErrorList, ValidationError 30 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput 30 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput, TimeInput 31 31 from django.core.files.uploadedfile import SimpleUploadedFile as UploadedFile 32 32 33 33 __all__ = ( 34 34 'Field', 'CharField', 'IntegerField', 35 35 'DEFAULT_DATE_INPUT_FORMATS', 'DateField', 36 36 'DEFAULT_TIME_INPUT_FORMATS', 'TimeField', 37 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField', 37 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField', 'TimeField', 38 38 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 39 39 'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField', 40 40 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', … … 311 311 ) 312 312 313 313 class TimeField(Field): 314 widget = TimeInput() 314 315 default_error_messages = { 315 316 'invalid': _(u'Enter a valid time.') 316 317 } -
django/forms/widgets.py
22 22 __all__ = ( 23 23 'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'PasswordInput', 24 24 'HiddenInput', 'MultipleHiddenInput', 25 'FileInput', 'DateTimeInput', 'T extarea', 'CheckboxInput',25 'FileInput', 'DateTimeInput', 'TimeInput', 'Textarea', 'CheckboxInput', 26 26 'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', 27 27 'CheckboxSelectMultiple', 'MultiWidget', 'SplitDateTimeWidget', 28 28 ) … … 301 301 value = value.strftime(self.format) 302 302 return super(DateTimeInput, self).render(name, value, attrs) 303 303 304 class TimeInput(Input): 305 input_type = 'text' 306 307 def render(self, name, value, attrs=None): 308 if value is None: 309 value = '' 310 elif hasattr(value, 'replace'): 311 value = value.replace(microsecond=0) 312 return super(TimeInput, self).render(name, value, attrs) 313 304 314 class CheckboxInput(Widget): 305 315 def __init__(self, attrs=None, check_test=bool): 306 316 super(CheckboxInput, self).__init__(attrs) -
tests/regressiontests/forms/widgets.py
1087 1087 u'<input type="text" name="date" value="2007-09-17 12:51:34" />' 1088 1088 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51)) 1089 1089 u'<input type="text" name="date" value="2007-09-17 12:51:00" />' 1090 1091 # TimeInput ############################################################### 1092 1093 >>> w = TimeInput() 1094 >>> w.render('time', None) 1095 u'<input type="text" name="time" />' 1096 >>> t = datetime.time(12, 51, 34, 482548) 1097 >>> print t 1098 12:51:34.482548 1099 1100 The microseconds are trimmed on display, by default. 1101 >>> w.render('time', t) 1102 u'<input type="text" name="time" value="12:51:34" />' 1103 >>> w.render('time', datetime.time(12, 51, 34)) 1104 u'<input type="text" name="time" value="12:51:34" />' 1105 >>> w.render('time', datetime.time(12, 51)) 1106 u'<input type="text" name="time" value="12:51:00" />' 1090 1107 """ 1108