Ticket #7509: splitdatetimewidget_formats.diff
File splitdatetimewidget_formats.diff, 2.0 KB (added by , 16 years ago) |
---|
-
django/newforms/widgets.py
371 371 label_for = u' for="%s"' % final_attrs['id'] 372 372 else: 373 373 label_for = '' 374 374 375 375 cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) 376 376 option_value = force_unicode(option_value) 377 377 rendered_cb = cb.render(name, option_value) … … 468 468 """ 469 469 A Widget that splits datetime input into two <input type="text"> boxes. 470 470 """ 471 def __init__(self, attrs=None): 472 widgets = (TextInput(attrs=attrs), TextInput(attrs=attrs)) 471 def __init__(self, attrs=None, date_format='%Y-%m-%d', time_format='%H:%M:%S'): 472 widgets = (DateTimeInput(attrs=attrs, format=date_format), 473 DateTimeInput(attrs=attrs, format=time_format)) 473 474 super(SplitDateTimeWidget, self).__init__(widgets, attrs) 474 475 475 476 def decompress(self, value): -
tests/regressiontests/forms/widgets.py
907 907 >>> w.render('date', [datetime.date(2006, 1, 10), datetime.time(7, 30)]) 908 908 u'<input type="text" name="date_0" value="2006-01-10" /><input type="text" name="date_1" value="07:30:00" />' 909 909 910 You can also pass custom date and time formats to the constructor. 911 >>> w = SplitDateTimeWidget(date_format='%m/%d/%Y', time_format='%I:%M:%S %p') 912 >>> w.render('date', datetime.datetime(2006, 1, 10, 7, 30)) 913 u'<input type="text" name="date_0" value="01/10/2006" /><input type="text" name="date_1" value="07:30:00 AM" />' 914 910 915 You can also pass 'attrs' to the constructor. In this case, the attrs will be 911 916 included on both widgets. 912 917 >>> w = SplitDateTimeWidget(attrs={'class': 'pretty'})