Ticket #3286: tests.py.diff
File tests.py.diff, 10.0 KB (added by , 18 years ago) |
---|
-
tests/regressiontests/forms/tests.py
1575 1575 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 1576 1576 <p><ul class="errorlist"><li>This field is required.</li></ul></p> 1577 1577 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 1578 >>> print p.as_div() 1579 <div><ul class="errorlist"><li>This field is required.</li></ul></div> 1580 <div><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></div> 1581 <div><ul class="errorlist"><li>This field is required.</li></ul></div> 1582 <div><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></div> 1583 <div><ul class="errorlist"><li>This field is required.</li></ul></div> 1584 <div><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></div> 1578 1585 1579 1586 If you don't pass any values to the Form's __init__(), or if you pass None, 1580 1587 the Form will be considered unbound and won't do any validation. Form.errors … … 1606 1613 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 1607 1614 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 1608 1615 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 1616 >>> print p.as_div() 1617 <div><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></div> 1618 <div><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></div> 1619 <div><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></div> 1609 1620 1610 1621 Unicode values are handled properly. 1611 1622 >>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) … … 1615 1626 u'<li><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>' 1616 1627 >>> p.as_p() 1617 1628 u'<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>' 1629 >>> p.as_div() 1630 u'<div><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></div>\n<div><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></div>\n<div><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></div>' 1618 1631 1619 1632 >>> p = Person({'last_name': u'Lennon'}) 1620 1633 >>> p.errors … … 1675 1688 <p><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p> 1676 1689 <p><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p> 1677 1690 <p><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p> 1691 >>> print p.as_div() 1692 <div><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></div> 1693 <div><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></div> 1694 <div><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></div> 1678 1695 1679 1696 If auto_id is any True value whose str() does not contain '%s', the "id" 1680 1697 attribute will be the name of the field. … … 1837 1854 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 1838 1855 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 1839 1856 </ul></p> 1857 >>> print f.as_div() 1858 <div><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></div> 1859 <div><label for="id_language_0">Language:</label> <ul> 1860 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 1861 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 1862 </ul></div> 1840 1863 1841 1864 MultipleChoiceField is a special case, as its data is required to be a list: 1842 1865 >>> class SongForm(Form): … … 2022 2045 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr> 2023 2046 <tr><th>Birthday:</th><td><input type="text" name="birthday" /></td></tr> 2024 2047 2025 HiddenInput widgets are displayed differently in the as_table(), as_ul() 2026 a nd as_p() output of a Form -- their verbose names are not displayed, and a2027 separate row is not displayed. They're displayed in the last row of the2048 HiddenInput widgets are displayed differently in the as_table(), as_ul(), 2049 as_p() and as_div() output of a Form -- their verbose names are not displayed, 2050 and a separate row is not displayed. They're displayed in the last row of the 2028 2051 form, directly after that row's form element. 2029 2052 >>> class Person(Form): 2030 2053 ... first_name = CharField() … … 2044 2067 <p>First name: <input type="text" name="first_name" /></p> 2045 2068 <p>Last name: <input type="text" name="last_name" /></p> 2046 2069 <p>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p> 2070 >>> print p.as_div() 2071 <div>First name: <input type="text" name="first_name" /></div> 2072 <div>Last name: <input type="text" name="last_name" /></div> 2073 <div>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></div> 2047 2074 2048 2075 With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label. 2049 2076 >>> p = Person(auto_id='id_%s') … … 2059 2086 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 2060 2087 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 2061 2088 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p> 2089 >>> print p.as_div() 2090 <div><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></div> 2091 <div><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></div> 2092 <div><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></div> 2062 2093 2063 2094 If a field with a HiddenInput has errors, the as_table() and as_ul() output 2064 2095 will include the error message(s) with the text "(Hidden field [fieldname]) " … … 2080 2111 <p>First name: <input type="text" name="first_name" value="John" /></p> 2081 2112 <p>Last name: <input type="text" name="last_name" value="Lennon" /></p> 2082 2113 <p>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p> 2114 >>> print p.as_div() 2115 <div><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></div> 2116 <div>First name: <input type="text" name="first_name" value="John" /></div> 2117 <div>Last name: <input type="text" name="last_name" value="Lennon" /></div> 2118 <div>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></div> 2083 2119 2120 2084 2121 A corner case: It's possible for a form to have only HiddenInputs. 2085 2122 >>> class TestForm(Form): 2086 2123 ... foo = CharField(widget=HiddenInput) … … 2092 2129 <input type="hidden" name="foo" /><input type="hidden" name="bar" /> 2093 2130 >>> print p.as_p() 2094 2131 <input type="hidden" name="foo" /><input type="hidden" name="bar" /> 2132 >>> print p.as_div() 2133 <input type="hidden" name="foo" /><input type="hidden" name="bar" /> 2095 2134 2096 2135 A Form's fields are displayed in the same order in which they were defined. 2097 2136 >>> class TestForm(Form): -
docs/newforms.txt
376 376 <li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li> 377 377 <li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li> 378 378 379 ``as_div()`` 380 ~~~~~~~~~~~ 381 382 ``Form.as_p()`` renders the form as a series of ``<div>`` tags, with each ``<div>`` 383 containing one field:: 384 385 >>> f = ContactForm() 386 >>> f.as_div() 387 u'<div><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></div>\n<div><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></div>\n<div><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></div>\n<div><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></div>' 388 >>> print f.as_div() 389 <div><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></div> 390 <div><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></div> 391 <div><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></div> 392 <div><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></div> 393 379 394 ``as_table()`` 380 395 ~~~~~~~~~~~~~~