Ticket #10288: datetimeinput.diff
File datetimeinput.diff, 1.6 KB (added by , 16 years ago) |
---|
-
django/forms/widgets.py
294 294 if format: 295 295 self.format = format 296 296 297 def render(self, name, value, attrs=None):297 def _format_value(self, value): 298 298 if value is None: 299 value =''299 return '' 300 300 elif hasattr(value, 'strftime'): 301 301 value = datetime_safe.new_datetime(value) 302 value = value.strftime(self.format) 302 return value.strftime(self.format) 303 return value 304 305 def render(self, name, value, attrs=None): 306 value = self._format_value(value) 303 307 return super(DateTimeInput, self).render(name, value, attrs) 304 308 309 def _has_changed(self, initial, data): 310 return super(DateTimeInput, self)._has_changed(self._format_value(initial), data) 311 305 312 class TimeInput(Input): 306 313 input_type = 'text' 307 314 -
tests/regressiontests/forms/widgets.py
1093 1093 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51)) 1094 1094 u'<input type="text" name="date" value="2007-09-17 12:51:00" />' 1095 1095 1096 Allow custom formats: 1097 >>> w = DateTimeInput(format='%d/%m/%Y') 1098 >>> w.render('date', d) 1099 u'<input type="text" name="date" value="17/09/2007" />' 1100 >>> w._has_changed(d, '17/09/2007') 1101 False 1102 1096 1103 # TimeInput ################################################################### 1097 1104 1098 1105 >>> w = TimeInput()