Ticket #4428: new_datetimefield_millisecond.diff
File new_datetimefield_millisecond.diff, 3.9 KB (added by , 17 years ago) |
---|
-
django/newforms/fields.py
11 11 from django.utils.encoding import StrAndUnicode, smart_unicode 12 12 13 13 from util import ErrorList, ValidationError 14 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple 14 from widgets import (TextInput, PasswordInput, HiddenInput, 15 MultipleHiddenInput, FileInput, CheckboxInput, Select, 16 NullBooleanSelect, SelectMultiple, DateTimeInput) 15 17 16 18 try: 17 19 from decimal import Decimal, DecimalException … … 284 286 ) 285 287 286 288 class DateTimeField(Field): 289 widget = DateTimeInput 287 290 def __init__(self, input_formats=None, *args, **kwargs): 288 291 super(DateTimeField, self).__init__(*args, **kwargs) 289 292 self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS -
django/newforms/widgets.py
7 7 except NameError: 8 8 from sets import Set as set # Python 2.3 fallback 9 9 10 try: 11 import settings 12 except ImportError: 13 pass 14 10 15 from itertools import chain 11 16 from django.utils.datastructures import MultiValueDict 12 17 from django.utils.html import escape … … 15 20 from util import flatatt 16 21 17 22 __all__ = ( 18 'Widget', 'TextInput', ' PasswordInput',23 'Widget', 'TextInput', 'DateTimeInput', 'PasswordInput', 19 24 'HiddenInput', 'MultipleHiddenInput', 20 25 'FileInput', 'Textarea', 'CheckboxInput', 21 26 'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', … … 84 89 class TextInput(Input): 85 90 input_type = 'text' 86 91 92 class DateTimeInput(Input): 93 input_type = 'text' 94 95 def __init__(self, attrs=None, format=None): 96 self.attrs = attrs or {} 97 self.format = format 98 if not self.format: 99 try: 100 self.format = settings.DATETIME_FORMAT 101 except: # Silently catch exceptions 102 self.format = 'Y-m-d h:i:s' 103 104 def render(self, name, value, attrs=None): 105 from django.utils.dateformat import format 106 return super(DateTimeInput, self).render(name, 107 format(value, self.format), 108 attrs) 109 87 110 class PasswordInput(Input): 88 111 input_type = 'password' 89 112 -
tests/regressiontests/forms/tests.py
848 848 >>> w.render('date', datetime.datetime(2006, 1, 10, 7, 30)) 849 849 u'<input type="text" class="pretty" value="2006-01-10" name="date_0" /><input type="text" class="pretty" value="07:30:00" name="date_1" />' 850 850 851 # DateTimeInput ############################################################### 852 853 >>> w = DateTimeInput() 854 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51, 34, 482548)) 855 u'<input type="text" name="date" value="2007-09-17 12:51:34" />' 856 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51, 34)) 857 u'<input type="text" name="date" value="2007-09-17 12:51:34" />' 858 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51)) 859 u'<input type="text" name="date" value="2007-09-17 12:51:00" />' 860 >>> w = DateTimeInput(format='h:i:s') 861 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51, 34, 482548)) 862 u'<input type="text" name="date" value="12:51:34" />' 863 >>> w = DateTimeInput(format='x:c:p') 864 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51, 34, 482548)) 865 u'<input type="text" name="date" value="x:c:p" />' 866 851 867 ########## 852 868 # Fields # 853 869 ##########