Ticket #5609: trunk2.diff
File trunk2.diff, 29.1 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
476 476 return smart_unicode(value) 477 477 478 478 def formfield(self, **kwargs): 479 defaults = {'max_length': self.max_length }479 defaults = {'max_length': self.max_length, 'length': 30} 480 480 defaults.update(kwargs) 481 481 return super(CharField, self).formfield(**defaults) 482 482 … … 484 484 class CommaSeparatedIntegerField(CharField): 485 485 def get_manipulator_field_objs(self): 486 486 return [oldforms.CommaSeparatedIntegerField] 487 488 def formfield(self, **kwargs): 489 defaults = {'length':20} 490 defaults.update(kwargs) 491 return super(CommaSeparatedIntegerField, self).formfield(**defaults) 487 492 488 493 class DateField(Field): 489 494 empty_strings_allowed = False … … 559 564 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')} 560 565 561 566 def formfield(self, **kwargs): 562 defaults = {'form_class': forms.DateField }567 defaults = {'form_class': forms.DateField, 'length':10, 'max_length':10} 563 568 defaults.update(kwargs) 564 569 return super(DateField, self).formfield(**defaults) 565 570 … … 624 629 time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 625 630 626 631 def formfield(self, **kwargs): 627 defaults = {'form_class': forms.DateTimeField }632 defaults = {'form_class': forms.DateTimeField, 'length':20, 'max_length':20} 628 633 defaults.update(kwargs) 629 634 return super(DateTimeField, self).formfield(**defaults) 630 635 … … 684 689 'max_digits': self.max_digits, 685 690 'decimal_places': self.decimal_places, 686 691 'form_class': forms.DecimalField, 692 'length': self.max_digits and self.max_digits + 2 or 30, 687 693 } 694 if self.max_digits: 695 defaults['max_length'] = self.max_digits + 2 688 696 defaults.update(kwargs) 689 697 return super(DecimalField, self).formfield(**defaults) 690 698 … … 703 711 validators.isValidEmail(field_data, all_data) 704 712 705 713 def formfield(self, **kwargs): 706 defaults = {'form_class': forms.EmailField }714 defaults = {'form_class': forms.EmailField, 'length': 50, 'max_length': self.max_length} 707 715 defaults.update(kwargs) 708 716 return super(EmailField, self).formfield(**defaults) 709 717 … … 869 877 return [oldforms.IntegerField] 870 878 871 879 def formfield(self, **kwargs): 872 defaults = {'form_class': forms.IntegerField }880 defaults = {'form_class': forms.IntegerField, 'length': 10} 873 881 defaults.update(kwargs) 874 882 return super(IntegerField, self).formfield(**defaults) 875 883 … … 886 894 validators.isValidIPAddress4(field_data, None) 887 895 888 896 def formfield(self, **kwargs): 889 defaults = {'form_class': forms.IPAddressField }897 defaults = {'form_class': forms.IPAddressField, 'length': 15, 'max_length': 15} 890 898 defaults.update(kwargs) 891 899 return super(IPAddressField, self).formfield(**defaults) 892 900 … … 915 923 916 924 def formfield(self, **kwargs): 917 925 from django.contrib.localflavor.us.forms import USPhoneNumberField 918 defaults = {'form_class': USPhoneNumberField} 926 defaults = {'form_class': USPhoneNumberField} 927 # 'length':12, 'max_length': 12 aren't used as USPhoneNumberField extends Field rather than CharField 919 928 defaults.update(kwargs) 920 929 return super(PhoneNumberField, self).formfield(**defaults) 921 930 … … 924 933 return [oldforms.PositiveIntegerField] 925 934 926 935 def formfield(self, **kwargs): 927 defaults = {'min_value': 0 }936 defaults = {'min_value': 0, 'length': 10} 928 937 defaults.update(kwargs) 929 938 return super(PositiveIntegerField, self).formfield(**defaults) 930 939 … … 933 942 return [oldforms.PositiveSmallIntegerField] 934 943 935 944 def formfield(self, **kwargs): 936 defaults = {'min_value': 0 }945 defaults = {'min_value': 0, 'length': 5, 'max_length': 5} 937 946 defaults.update(kwargs) 938 947 return super(PositiveSmallIntegerField, self).formfield(**defaults) 939 948 … … 950 959 def get_manipulator_field_objs(self): 951 960 return [oldforms.SmallIntegerField] 952 961 962 def formfield(self, **kwargs): 963 defaults = {'length': 5, 'max_length': 5} 964 defaults.update(kwargs) 965 return super(SmallIntegerField, self).formfield(**defaults) 966 953 967 class TextField(Field): 954 968 def get_manipulator_field_objs(self): 955 969 return [oldforms.LargeTextField] … … 1016 1030 return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')} 1017 1031 1018 1032 def formfield(self, **kwargs): 1019 defaults = {'form_class': forms.TimeField }1033 defaults = {'form_class': forms.TimeField, 'length': 8, 'max_length': 8} 1020 1034 defaults.update(kwargs) 1021 1035 return super(TimeField, self).formfield(**defaults) 1022 1036 … … 1035 1049 return "CharField" 1036 1050 1037 1051 def formfield(self, **kwargs): 1038 defaults = {'form_class': forms.URLField, 'verify_exists': self.verify_exists }1052 defaults = {'form_class': forms.URLField, 'verify_exists': self.verify_exists, 'length': 50} 1039 1053 defaults.update(kwargs) 1040 1054 return super(URLField, self).formfield(**defaults) 1041 1055 -
django/newforms/fields.py
20 20 from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str 21 21 22 22 from util import ErrorList, ValidationError 23 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput23 from widgets import WidgetDict, TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput 24 24 25 25 26 26 __all__ = ( … … 110 110 any HTML attributes that should be added to the Widget, based on this 111 111 Field. 112 112 """ 113 return {} 113 if self.required: 114 return WidgetDict({'class': 'required'}) 115 return WidgetDict() 114 116 115 117 def __deepcopy__(self, memo): 116 118 result = copy.copy(self) … … 124 126 'min_length': _(u'Ensure this value has at least %(min)d characters (it has %(length)d).'), 125 127 } 126 128 127 def __init__(self, max_length=None, min_length=None, *args, **kwargs):128 self.max_length, self.min_length = max_length, min_length129 def __init__(self, max_length=None, min_length=None, length=None, *args, **kwargs): 130 self.max_length, self.min_length, self.length = max_length, min_length, length 129 131 super(CharField, self).__init__(*args, **kwargs) 130 132 131 133 def clean(self, value): … … 142 144 return value 143 145 144 146 def widget_attrs(self, widget): 145 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 147 attrs = super(CharField, self).widget_attrs(widget) 148 if self.length is not None: 149 attrs['size'] = str(self.length) 150 if self.max_length is not None: 146 151 # The HTML attribute is maxlength, not max_length. 147 return {'maxlength': str(self.max_length)} 152 attrs['maxlength'] = str(self.max_length) 153 return attrs 148 154 149 class IntegerField( Field):155 class IntegerField(CharField): 150 156 default_error_messages = { 151 157 'invalid': _(u'Enter a whole number.'), 152 158 'max_value': _(u'Ensure this value is less than or equal to %s.'), … … 183 189 } 184 190 185 191 def __init__(self, max_value=None, min_value=None, *args, **kwargs): 192 super(FloatField, self).__init__(*args, **kwargs) 186 193 self.max_value, self.min_value = max_value, min_value 187 Field.__init__(self, *args, **kwargs)188 194 189 195 def clean(self, value): 190 196 """ … … 204 210 raise ValidationError(self.error_messages['min_value'] % self.min_value) 205 211 return value 206 212 207 class DecimalField( Field):213 class DecimalField(CharField): 208 214 default_error_messages = { 209 215 'invalid': _(u'Enter a number.'), 210 216 'max_value': _(u'Ensure this value is less than or equal to %s.'), … … 215 221 } 216 222 217 223 def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs): 224 super(DecimalField, self).__init__(*args, **kwargs) 218 225 self.max_value, self.min_value = max_value, min_value 219 226 self.max_digits, self.decimal_places = max_digits, decimal_places 220 Field.__init__(self, *args, **kwargs)221 227 222 228 def clean(self, value): 223 229 """ … … 257 263 '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' 258 264 ) 259 265 260 class DateField( Field):266 class DateField(CharField): 261 267 default_error_messages = { 262 268 'invalid': _(u'Enter a valid date.'), 263 269 } … … 290 296 '%H:%M', # '14:30' 291 297 ) 292 298 293 class TimeField( Field):299 class TimeField(CharField): 294 300 default_error_messages = { 295 301 'invalid': _(u'Enter a valid time.') 296 302 } … … 328 334 '%m/%d/%y', # '10/25/06' 329 335 ) 330 336 331 class DateTimeField( Field):337 class DateTimeField(CharField): 332 338 widget = DateTimeInput 333 339 default_error_messages = { 334 340 'invalid': _(u'Enter a valid date/time.'), … … 375 381 error_messages = kwargs.get('error_messages') or {} 376 382 error_messages['invalid'] = error_message 377 383 kwargs['error_messages'] = error_messages 378 super(RegexField, self).__init__(max_length ,min_length, *args, **kwargs)384 super(RegexField, self).__init__(max_length=max_length, min_length=min_length, *args, **kwargs) 379 385 if isinstance(regex, basestring): 380 386 regex = re.compile(regex) 381 387 self.regex = regex … … 493 499 'invalid_link': _(u'This URL appears to be a broken link.'), 494 500 } 495 501 496 def __init__(self, max_length=None, min_length=None, verify_exists=False,502 def __init__(self, max_length=None, min_length=None, length=None, verify_exists=False, 497 503 validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs): 498 super(URLField, self).__init__( url_re, max_length, min_length, *args,499 **kwargs)504 super(URLField, self).__init__(regex=url_re, max_length=max_length, 505 min_length=min_length, length=length, *args, **kwargs) 500 506 self.verify_exists = verify_exists 501 507 self.user_agent = validator_user_agent 502 508 … … 557 563 558 564 def __init__(self, choices=(), required=True, widget=None, label=None, 559 565 initial=None, help_text=None, *args, **kwargs): 560 super(ChoiceField, self).__init__(required, widget, label, initial, 561 help_text, *args, **kwargs) 566 super(ChoiceField, self).__init__(required=required, widget=widget, label=label, 567 initial=initial, help_text=help_text, 568 *args, **kwargs) 562 569 self.choices = choices 563 570 564 571 def _get_choices(self): … … 725 732 if 'error_messages' in kwargs: 726 733 errors.update(kwargs['error_messages']) 727 734 fields = ( 728 DateField(error_messages={'invalid': errors['invalid_date']} ),729 TimeField(error_messages={'invalid': errors['invalid_time']} ),735 DateField(error_messages={'invalid': errors['invalid_date']}, max_length=10), 736 TimeField(error_messages={'invalid': errors['invalid_time']}, max_length=8), 730 737 ) 731 super(SplitDateTimeField, self).__init__(fields , *args, **kwargs)738 super(SplitDateTimeField, self).__init__(fields=fields, *args, **kwargs) 732 739 733 740 def compress(self, data_list): 734 741 if data_list: … … 749 756 } 750 757 751 758 def __init__(self, *args, **kwargs): 752 super(IPAddressField, self).__init__( ipv4_re, *args, **kwargs)759 super(IPAddressField, self).__init__(regex=ipv4_re, *args, **kwargs) -
django/newforms/widgets.py
18 18 from util import flatatt 19 19 20 20 __all__ = ( 21 'Widget ', 'TextInput', 'PasswordInput',21 'WidgetDict', 'Widget', 'TextInput', 'PasswordInput', 22 22 'HiddenInput', 'MultipleHiddenInput', 23 23 'FileInput', 'DateTimeInput', 'Textarea', 'CheckboxInput', 24 24 'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', 25 25 'CheckboxSelectMultiple', 'MultiWidget', 'SplitDateTimeWidget', 26 26 ) 27 27 28 29 class WidgetDict(dict): 30 """ 31 Tracks most attributes normally - except css classes, which are 32 appended instead of replaced when you set/update the variable. 33 34 If you truly need to override the css class value, just delete and reset it 35 """ 36 def _css_class_string(self, value): 37 """ 38 Returns string containing combination of all classes 39 """ 40 if not value: 41 return self.get('class', '') 42 my_classes = set(self.get('class', '').split(' ')) 43 my_classes.update(value.split(' ')) 44 my_classes.discard('') 45 return ' '.join(my_classes) 46 47 def __setitem__(self, key, value): 48 if key == 'class': 49 value = self._css_class_string(value) 50 super(WidgetDict, self).__setitem__(key, value) 51 52 def update(self, new_dict): 53 my_dict = new_dict.copy() 54 if my_dict.has_key('class'): 55 my_dict['class'] = self._css_class_string(my_dict.get('class')) 56 super(WidgetDict, self).update(my_dict) 57 28 58 class Widget(object): 29 59 is_hidden = False # Determines whether this corresponds to an <input type="hidden">. 30 60 needs_multipart_form = False # Determines does this widget need multipart-encrypted form 31 61 32 62 def __init__(self, attrs=None): 33 63 if attrs is not None: 34 self.attrs = attrs.copy()64 self.attrs = WidgetDict(attrs) 35 65 else: 36 self.attrs = {}66 self.attrs = WidgetDict() 37 67 38 68 def __deepcopy__(self, memo): 39 69 obj = copy.copy(self) … … 52 82 53 83 def build_attrs(self, extra_attrs=None, **kwargs): 54 84 "Helper function for building an attribute dictionary." 55 attrs = dict(self.attrs, **kwargs) 85 attrs = WidgetDict(self.attrs) 86 attrs.update(kwargs) 56 87 if extra_attrs: 57 88 attrs.update(extra_attrs) 58 89 return attrs -
tests/regressiontests/forms/extra.py
232 232 ... field1 = ComplexField(widget=w) 233 233 >>> f = ComplexFieldForm() 234 234 >>> print f 235 <tr><th><label for="id_field1_0">Field1:</label></th><td><input type="text" name="field1_0" id="id_field1_0" />236 <select multiple="multiple" name="field1_1" id="id_field1_1">235 <tr><th><label for="id_field1_0">Field1:</label></th><td><input id="id_field1_0" type="text" name="field1_0" class="required" /> 236 <select multiple="multiple" id="id_field1_1" name="field1_1" class="required"> 237 237 <option value="J">John</option> 238 238 <option value="P">Paul</option> 239 239 <option value="G">George</option> 240 240 <option value="R">Ringo</option> 241 241 </select> 242 <input type="text" name="field1_2_0" id="id_field1_2_0" /><input type="text" name="field1_2_1" id="id_field1_2_1" /></td></tr>242 <input id="id_field1_2_0" type="text" name="field1_2_0" class="required" /><input id="id_field1_2_1" type="text" name="field1_2_1" class="required" /></td></tr> 243 243 244 244 >>> f = ComplexFieldForm({'field1_0':'some text','field1_1':['J','P'], 'field1_2_0':'2007-04-25', 'field1_2_1':'06:24:00'}) 245 245 >>> print f 246 <tr><th><label for="id_field1_0">Field1:</label></th><td><input type="text" name="field1_0" value="some text" id="id_field1_0" />247 <select multiple="multiple" name="field1_1" id="id_field1_1">246 <tr><th><label for="id_field1_0">Field1:</label></th><td><input id="id_field1_0" type="text" name="field1_0" value="some text" class="required" /> 247 <select multiple="multiple" id="id_field1_1" name="field1_1" class="required"> 248 248 <option value="J" selected="selected">John</option> 249 249 <option value="P" selected="selected">Paul</option> 250 250 <option value="G">George</option> 251 251 <option value="R">Ringo</option> 252 252 </select> 253 <input type="text" name="field1_2_0" value="2007-04-25" id="id_field1_2_0" /><input type="text" name="field1_2_1" value="06:24:00" id="id_field1_2_1" /></td></tr>253 <input id="id_field1_2_0" type="text" name="field1_2_0" value="2007-04-25" class="required" /><input id="id_field1_2_1" type="text" name="field1_2_1" value="06:24:00" class="required" /></td></tr> 254 254 255 255 >>> f.cleaned_data 256 256 {'field1': u'some text,JP,2007-04-25 06:24:00'} … … 373 373 >>> print f.as_p() 374 374 <p>Name: <input type="text" name="name" maxlength="50" /></p> 375 375 <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> 376 <p>Email: <input type="text" name="email" value="invalid" /></p>376 <p>Email: <input type="text" class="required" value="invalid" name="email" /></p> 377 377 <div class="errorlist"><div class="error">This field is required.</div></div> 378 <p>Comment: <input type="text" name="comment" /></p>378 <p>Comment: <input type="text" class="required" name="comment" /></p> 379 379 380 380 ################################# 381 381 # Test multipart-encoded form # -
tests/regressiontests/forms/forms.py
39 39 >>> p.cleaned_data 40 40 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 41 41 >>> print p['first_name'] 42 <input type="text" name="first_name" value="John" id="id_first_name" />42 <input id="id_first_name" type="text" class="required" value="John" name="first_name" /> 43 43 >>> print p['last_name'] 44 <input type="text" name="last_name" value="Lennon" id="id_last_name" />44 <input id="id_last_name" type="text" class="required" value="Lennon" name="last_name" /> 45 45 >>> print p['birthday'] 46 <input type="text" name="birthday" value="1940-10-9" id="id_birthday" />46 <input id="id_birthday" type="text" class="required" value="1940-10-9" name="birthday" /> 47 47 >>> print p['nonexistentfield'] 48 48 Traceback (most recent call last): 49 49 ... … … 51 51 52 52 >>> for boundfield in p: 53 53 ... print boundfield 54 <input type="text" name="first_name" value="John" id="id_first_name" />55 <input type="text" name="last_name" value="Lennon" id="id_last_name" />56 <input type="text" name="birthday" value="1940-10-9" id="id_birthday" />54 <input id="id_first_name" type="text" class="required" value="John" name="first_name" /> 55 <input id="id_last_name" type="text" class="required" value="Lennon" name="last_name" /> 56 <input id="id_birthday" type="text" class="required" value="1940-10-9" name="birthday" /> 57 57 >>> for boundfield in p: 58 58 ... print boundfield.label, boundfield.data 59 59 First name John 60 60 Last name Lennon 61 61 Birthday 1940-10-9 62 62 >>> print p 63 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>64 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>65 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>63 <tr><th><label for="id_first_name">First name:</label></th><td><input id="id_first_name" type="text" class="required" value="John" name="first_name" /></td></tr> 64 <tr><th><label for="id_last_name">Last name:</label></th><td><input id="id_last_name" type="text" class="required" value="Lennon" name="last_name" /></td></tr> 65 <tr><th><label for="id_birthday">Birthday:</label></th><td><input id="id_birthday" type="text" class="required" value="1940-10-9" name="birthday" /></td></tr> 66 66 67 67 Empty dictionaries are valid, too. 68 68 >>> p = Person({}) … … 77 77 ... 78 78 AttributeError: 'Person' object has no attribute 'cleaned_data' 79 79 >>> print p 80 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>81 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>82 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>80 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_first_name" type="text" class="required" name="first_name" /></td></tr> 81 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_last_name" type="text" class="required" name="last_name" /></td></tr> 82 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_birthday" type="text" class="required" name="birthday" /></td></tr> 83 83 >>> print p.as_table() 84 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>85 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>86 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>84 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_first_name" class="required" type="text" name="first_name" /></td></tr> 85 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_last_name" type="text" class="required" name="last_name" /></td></tr> 86 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_birthday" type="text" class="required" name="birthday" /></td></tr> 87 87 >>> print p.as_ul() 88 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>89 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>90 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>88 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name:</label> <input id="id_first_name" type="text" class="required" name="first_name" /></li> 89 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input id="id_last_name" type="text" class="required" name="last_name" /></li> 90 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input id="id_birthday" type="text" class="required" name="birthday" /></li> 91 91 >>> print p.as_p() 92 92 <ul class="errorlist"><li>This field is required.</li></ul> 93 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>93 <p><label for="id_first_name">First name:</label> <input id="id_first_name" type="text" class="required" name="first_name" /></p> 94 94 <ul class="errorlist"><li>This field is required.</li></ul> 95 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>95 <p><label for="id_last_name">Last name:</label> <input id="id_last_name" type="text" class="required" name="last_name" /></p> 96 96 <ul class="errorlist"><li>This field is required.</li></ul> 97 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>97 <p><label for="id_birthday">Birthday:</label> <input id="id_birthday" type="text" class="required" name="birthday" /></p> 98 98 99 99 If you don't pass any values to the Form's __init__(), or if you pass None, 100 100 the Form will be considered unbound and won't do any validation. Form.errors -
tests/regressiontests/forms/widgets.py
19 19 render itself, given a field name and some data. Widgets don't perform 20 20 validation. 21 21 22 WidgetDict appends css class information instead of overwriting it. 23 24 # WidgetDict ################################################################## 25 >>> w = WidgetDict({'class': 'test run'}) 26 >>> w['class'] = 'another' 27 >>> print w['class'] 28 test run another 29 >>> w.update({'class': 'fourth', 'ignore': 'foo'}) 30 >>> print w['class'] 31 test another run fourth 32 22 33 # TextInput Widget ############################################################ 23 34 24 35 >>> w = TextInput() … … 48 59 'attrs' passed to render() get precedence over those passed to the constructor: 49 60 >>> w = TextInput(attrs={'class': 'pretty'}) 50 61 >>> w.render('email', '', attrs={'class': 'special'}) 51 u'<input type="text" class=" special" name="email" />'62 u'<input type="text" class="pretty special" name="email" />' 52 63 53 64 # PasswordInput Widget ############################################################ 54 65 … … 74 85 'attrs' passed to render() get precedence over those passed to the constructor: 75 86 >>> w = PasswordInput(attrs={'class': 'pretty'}) 76 87 >>> w.render('email', '', attrs={'class': 'special'}) 77 u'<input type="password" class=" special" name="email" />'88 u'<input type="password" class="pretty special" name="email" />' 78 89 79 90 >>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 80 91 u'<input type="password" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />' … … 119 130 'attrs' passed to render() get precedence over those passed to the constructor: 120 131 >>> w = HiddenInput(attrs={'class': 'pretty'}) 121 132 >>> w.render('email', '', attrs={'class': 'special'}) 122 u'<input type="hidden" class=" special" name="email" />'133 u'<input type="hidden" class="pretty special" name="email" />' 123 134 124 135 >>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 125 136 u'<input type="hidden" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />' … … 127 138 'attrs' passed to render() get precedence over those passed to the constructor: 128 139 >>> w = HiddenInput(attrs={'class': 'pretty'}) 129 140 >>> w.render('email', '', attrs={'class': 'special'}) 130 u'<input type="hidden" class=" special" name="email" />'141 u'<input type="hidden" class="pretty special" name="email" />' 131 142 132 143 Boolean values are rendered to their string forms ("True" and "False"). 133 144 >>> w = HiddenInput() … … 166 177 'attrs' passed to render() get precedence over those passed to the constructor: 167 178 >>> w = MultipleHiddenInput(attrs={'class': 'pretty'}) 168 179 >>> w.render('email', ['foo@example.com'], attrs={'class': 'special'}) 169 u'<input type="hidden" class=" special" value="foo@example.com" name="email" />'180 u'<input type="hidden" class="pretty special" value="foo@example.com" name="email" />' 170 181 171 182 >>> w.render('email', ['ŠĐĆŽćžšđ'], attrs={'class': 'fun'}) 172 183 u'<input type="hidden" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />' … … 174 185 'attrs' passed to render() get precedence over those passed to the constructor: 175 186 >>> w = MultipleHiddenInput(attrs={'class': 'pretty'}) 176 187 >>> w.render('email', ['foo@example.com'], attrs={'class': 'special'}) 177 u'<input type="hidden" class=" special" value="foo@example.com" name="email" />'188 u'<input type="hidden" class="pretty special" value="foo@example.com" name="email" />' 178 189 179 190 # FileInput Widget ############################################################ 180 191 … … 228 239 'attrs' passed to render() get precedence over those passed to the constructor: 229 240 >>> w = Textarea(attrs={'class': 'pretty'}) 230 241 >>> w.render('msg', '', attrs={'class': 'special'}) 231 u'<textarea rows="10" cols="40" name="msg" class=" special"></textarea>'242 u'<textarea rows="10" cols="40" name="msg" class="pretty special"></textarea>' 232 243 233 244 >>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 234 245 u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>' … … 261 272 'attrs' passed to render() get precedence over those passed to the constructor: 262 273 >>> w = CheckboxInput(attrs={'class': 'pretty'}) 263 274 >>> w.render('is_cool', '', attrs={'class': 'special'}) 264 u'<input type="checkbox" class=" special" name="is_cool" />'275 u'<input type="checkbox" class="pretty special" name="is_cool" />' 265 276 266 277 You can pass 'check_test' to the constructor. This is a callable that takes the 267 278 value and returns True if the box should be checked.