Ticket #3334: form_tests.diff
File form_tests.diff, 1.8 KB (added by , 18 years ago) |
---|
-
tests/regressiontests/forms/tests.py
2063 2063 >>> f.clean_data 2064 2064 {'username': u'adrian', 'password1': u'foo', 'password2': u'foo'} 2065 2065 2066 # Dynamic construction ######################################################## 2067 2066 2068 It's possible to construct a Form dynamically by adding to the self.fields 2067 2069 dictionary in __init__(). Don't forget to call Form.__init__() within the 2068 2070 subclass' __init__(). … … 2078 2080 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr> 2079 2081 <tr><th>Birthday:</th><td><input type="text" name="birthday" /></td></tr> 2080 2082 2083 Instances of a dynamic form should not persist fields from one 2084 form instance to the next 2085 >>> class MyForm(Form): 2086 ... def __init__(self, data=None, auto_id=False, field_list=[]): 2087 ... Form.__init__(self, data, auto_id) 2088 ... for field in field_list: 2089 ... self.fields[field[0]] = field[1] 2090 ... 2091 >>> field_list = ( ('field1', CharField()), ('field2', CharField()) ) 2092 >>> my_form = MyForm(field_list=field_list) 2093 >>> print my_form 2094 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr> 2095 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr> 2096 >>> field_list = ( ('field3', CharField()), ('field4', CharField()) ) 2097 >>> my_form = MyForm(field_list=field_list) 2098 >>> print my_form 2099 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr> 2100 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr> 2101 2081 2102 HiddenInput widgets are displayed differently in the as_table(), as_ul() 2082 2103 and as_p() output of a Form -- their verbose names are not displayed, and a 2083 2104 separate row is not displayed. They're displayed in the last row of the