Changeset 4192
- Timestamp:
- 12/10/06 20:38:18 (2 years ago)
- Files:
-
- django/trunk/django/newforms/forms.py (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/forms.py
r4188 r4192 37 37 __metaclass__ = DeclarativeFieldsMetaclass 38 38 39 def __init__(self, data=None, auto_id= False): # TODO: prefix stuff39 def __init__(self, data=None, auto_id='id_%s'): # TODO: prefix stuff 40 40 self.ignore_errors = data is None 41 41 self.data = data or {} django/trunk/tests/regressiontests/forms/tests.py
r4188 r4192 1328 1328 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 1329 1329 >>> print p['first_name'] 1330 <input type="text" name="first_name" value="John" />1330 <input type="text" name="first_name" value="John" id="id_first_name" /> 1331 1331 >>> print p['last_name'] 1332 <input type="text" name="last_name" value="Lennon" />1332 <input type="text" name="last_name" value="Lennon" id="id_last_name" /> 1333 1333 >>> print p['birthday'] 1334 <input type="text" name="birthday" value="1940-10-9" />1334 <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /> 1335 1335 >>> for boundfield in p: 1336 1336 ... print boundfield 1337 <input type="text" name="first_name" value="John" />1338 <input type="text" name="last_name" value="Lennon" />1339 <input type="text" name="birthday" value="1940-10-9" />1337 <input type="text" name="first_name" value="John" id="id_first_name" /> 1338 <input type="text" name="last_name" value="Lennon" id="id_last_name" /> 1339 <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /> 1340 1340 >>> for boundfield in p: 1341 1341 ... print boundfield.label, boundfield.data … … 1344 1344 Birthday 1940-10-9 1345 1345 >>> print p 1346 <tr><td> First name:</td><td><input type="text" name="first_name" value="John" /></td></tr>1347 <tr><td> Last name:</td><td><input type="text" name="last_name" value="Lennon" /></td></tr>1348 <tr><td> Birthday:</td><td><input type="text" name="birthday" value="1940-10-9" /></td></tr>1346 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr> 1347 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr> 1348 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr> 1349 1349 1350 1350 Empty dictionaries are valid, too. … … 1356 1356 >>> print p 1357 1357 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1358 <tr><td> First name:</td><td><input type="text" name="first_name" /></td></tr>1358 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 1359 1359 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1360 <tr><td> Last name:</td><td><input type="text" name="last_name" /></td></tr>1360 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 1361 1361 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1362 <tr><td> Birthday:</td><td><input type="text" name="birthday" /></td></tr>1362 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 1363 1363 >>> print p.as_table() 1364 1364 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1365 <tr><td> First name:</td><td><input type="text" name="first_name" /></td></tr>1365 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 1366 1366 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1367 <tr><td> Last name:</td><td><input type="text" name="last_name" /></td></tr>1367 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 1368 1368 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 1369 <tr><td> Birthday:</td><td><input type="text" name="birthday" /></td></tr>1369 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 1370 1370 >>> print p.as_ul() 1371 <li><ul class="errorlist"><li>This field is required.</li></ul> First name: <input type="text" name="first_name" /></li>1372 <li><ul class="errorlist"><li>This field is required.</li></ul> Last name: <input type="text" name="last_name" /></li>1373 <li><ul class="errorlist"><li>This field is required.</li></ul> Birthday: <input type="text" name="birthday" /></li>1371 <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> 1372 <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> 1373 <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> 1374 1374 >>> print p.as_p() 1375 1375 <p><ul class="errorlist"><li>This field is required.</li></ul></p> 1376 <p> First name: <input type="text" name="first_name" /></p>1376 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 1377 1377 <p><ul class="errorlist"><li>This field is required.</li></ul></p> 1378 <p> Last name: <input type="text" name="last_name" /></p>1378 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 1379 1379 <p><ul class="errorlist"><li>This field is required.</li></ul></p> 1380 <p> Birthday: <input type="text" name="birthday" /></p>1380 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 1381 1381 1382 1382 If you don't pass any values to the Form's __init__(), or if you pass None, … … 1389 1389 False 1390 1390 >>> print p 1391 <tr><td> First name:</td><td><input type="text" name="first_name" /></td></tr>1392 <tr><td> Last name:</td><td><input type="text" name="last_name" /></td></tr>1393 <tr><td> Birthday:</td><td><input type="text" name="birthday" /></td></tr>1391 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 1392 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 1393 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 1394 1394 >>> print p.as_table() 1395 <tr><td> First name:</td><td><input type="text" name="first_name" /></td></tr>1396 <tr><td> Last name:</td><td><input type="text" name="last_name" /></td></tr>1397 <tr><td> Birthday:</td><td><input type="text" name="birthday" /></td></tr>1395 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 1396 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 1397 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 1398 1398 >>> print p.as_ul() 1399 <li> First name: <input type="text" name="first_name" /></li>1400 <li> Last name: <input type="text" name="last_name" /></li>1401 <li> Birthday: <input type="text" name="birthday" /></li>1399 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li> 1400 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li> 1401 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li> 1402 1402 >>> print p.as_p() 1403 <p> First name: <input type="text" name="first_name" /></p>1404 <p> Last name: <input type="text" name="last_name" /></p>1405 <p> Birthday: <input type="text" name="birthday" /></p>1403 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 1404 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 1405 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 1406 1406 1407 1407 Unicode values are handled properly. 1408 1408 >>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) 1409 1409 >>> p.as_table() 1410 u'<tr><td> First name:</td><td><input type="text" name="first_name" value="John" /></td></tr>\n<tr><td>Last name:</td><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></td></tr>\n<tr><td>Birthday:</td><td><input type="text" name="birthday" value="1940-10-9" /></td></tr>'1410 u'<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>' 1411 1411 >>> p.as_ul() 1412 u'<li> First name: <input type="text" name="first_name" value="John" /></li>\n<li>Last name: <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></li>\n<li>Birthday: <input type="text" name="birthday" value="1940-10-9" /></li>'1412 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>' 1413 1413 >>> p.as_p() 1414 u'<p> First name: <input type="text" name="first_name" value="John" /></p>\n<p>Last name: <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></p>\n<p>Birthday: <input type="text" name="birthday" value="1940-10-9" /></p>'1414 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>' 1415 1415 1416 1416 >>> p = Person({'last_name': u'Lennon'}) … … 1438 1438 >>> p = Person() 1439 1439 >>> print p['first_name'] 1440 <input type="text" name="first_name" />1440 <input type="text" name="first_name" id="id_first_name" /> 1441 1441 >>> print p['last_name'] 1442 <input type="text" name="last_name" />1442 <input type="text" name="last_name" id="id_last_name" /> 1443 1443 >>> print p['birthday'] 1444 <input type="text" name="birthday" />1444 <input type="text" name="birthday" id="id_birthday" /> 1445 1445 1446 1446 "auto_id" tells the Form to add an "id" attribute to each form element. … … 1448 1448 into which the field's name will be inserted. It will also put a <label> around 1449 1449 the human-readable labels for a field. 1450 >>> p = Person(auto_id=' id_%s')1450 >>> p = Person(auto_id='%s_id') 1451 1451 >>> print p.as_table() 1452 <tr><td><label for=" id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr>1453 <tr><td><label for=" id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr>1454 <tr><td><label for=" id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr>1452 <tr><td><label for="first_name_id">First name:</label></td><td><input type="text" name="first_name" id="first_name_id" /></td></tr> 1453 <tr><td><label for="last_name_id">Last name:</label></td><td><input type="text" name="last_name" id="last_name_id" /></td></tr> 1454 <tr><td><label for="birthday_id">Birthday:</label></td><td><input type="text" name="birthday" id="birthday_id" /></td></tr> 1455 1455 >>> print p.as_ul() 1456 <li><label for=" id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>1457 <li><label for=" id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>1458 <li><label for=" id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>1456 <li><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></li> 1457 <li><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></li> 1458 <li><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></li> 1459 1459 >>> print p.as_p() 1460 <p><label for=" id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>1461 <p><label for=" id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>1462 <p><label for=" id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>1460 <p><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p> 1461 <p><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p> 1462 <p><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p> 1463 1463 1464 1464 If auto_id is any True value whose str() does not contain '%s', the "id" … … 1501 1501 ... email = EmailField() 1502 1502 ... get_spam = BooleanField() 1503 >>> f = SignupForm( )1503 >>> f = SignupForm(auto_id=False) 1504 1504 >>> print f['email'] 1505 1505 <input type="text" name="email" /> … … 1507 1507 <input type="checkbox" name="get_spam" /> 1508 1508 1509 >>> f = SignupForm({'email': 'test@example.com', 'get_spam': True} )1509 >>> f = SignupForm({'email': 'test@example.com', 'get_spam': True}, auto_id=False) 1510 1510 >>> print f['email'] 1511 1511 <input type="text" name="email" value="test@example.com" /> … … 1517 1517 ... subject = CharField() 1518 1518 ... message = CharField(widget=Textarea) 1519 >>> f = ContactForm( )1519 >>> f = ContactForm(auto_id=False) 1520 1520 >>> print f['subject'] 1521 1521 <input type="text" name="subject" /> … … 1536 1536 ... subject = CharField() 1537 1537 ... message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20})) 1538 >>> f = ContactForm( )1538 >>> f = ContactForm(auto_id=False) 1539 1539 >>> print f['message'] 1540 1540 <textarea rows="80" cols="20" name="message"></textarea> … … 1544 1544 >>> f['message'].as_text() 1545 1545 u'<input type="text" name="message" />' 1546 >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'} )1546 >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False) 1547 1547 >>> f['subject'].as_textarea() 1548 1548 u'<textarea name="subject">Hello</textarea>' … … 1556 1556 ... name = CharField() 1557 1557 ... language = ChoiceField(choices=[('P', 'Python'), ('J', 'Java')]) 1558 >>> f = FrameworkForm( )1558 >>> f = FrameworkForm(auto_id=False) 1559 1559 >>> print f['language'] 1560 1560 <select name="language"> … … 1562 1562 <option value="J">Java</option> 1563 1563 </select> 1564 >>> f = FrameworkForm({'name': 'Django', 'language': 'P'} )1564 >>> f = FrameworkForm({'name': 'Django', 'language': 'P'}, auto_id=False) 1565 1565 >>> print f['language'] 1566 1566 <select name="language"> … … 1573 1573 ... name = CharField() 1574 1574 ... language = ChoiceField(choices=[('P', 'Python'), ('J', 'Java')], widget=RadioSelect) 1575 >>> f = FrameworkForm( )1575 >>> f = FrameworkForm(auto_id=False) 1576 1576 >>> print f['language'] 1577 1577 <ul> … … 1628 1628 ... name = CharField() 1629 1629 ... composers = MultipleChoiceField() 1630 >>> f = SongForm( )1630 >>> f = SongForm(auto_id=False) 1631 1631 >>> print f['composers'] 1632 1632 <select multiple="multiple" name="composers"> … … 1635 1635 ... name = CharField() 1636 1636 ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')]) 1637 >>> f = SongForm( )1637 >>> f = SongForm(auto_id=False) 1638 1638 >>> print f['composers'] 1639 1639 <select multiple="multiple" name="composers"> … … 1641 1641 <option value="P">Paul McCartney</option> 1642 1642 </select> 1643 >>> f = SongForm({'name': 'Yesterday', 'composers': ['P']} )1643 >>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}, auto_id=False) 1644 1644 >>> print f['name'] 1645 1645 <input type="text" name="name" value="Yesterday" /> … … 1654 1654 ... name = CharField() 1655 1655 ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=CheckboxSelectMultiple) 1656 >>> f = SongForm( )1656 >>> f = SongForm(auto_id=False) 1657 1657 >>> print f['composers'] 1658 1658 <ul> … … 1660 1660 <li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 1661 1661 </ul> 1662 >>> f = SongForm({'composers': ['J']} )1662 >>> f = SongForm({'composers': ['J']}, auto_id=False) 1663 1663 >>> print f['composers'] 1664 1664 <ul> … … 1666 1666 <li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 1667 1667 </ul> 1668 >>> f = SongForm({'composers': ['J', 'P']} )1668 >>> f = SongForm({'composers': ['J', 'P']}, auto_id=False) 1669 1669 >>> print f['composers'] 1670 1670 <ul> … … 1675 1675 When using CheckboxSelectMultiple, the framework expects a list of input and 1676 1676 returns a list of input. 1677 >>> f = SongForm({'name': 'Yesterday'} )1677 >>> f = SongForm({'name': 'Yesterday'}, auto_id=False) 1678 1678 >>> f.errors 1679 1679 {'composers': [u'This field is required.']} 1680 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J']} )1680 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J']}, auto_id=False) 1681 1681 >>> f.errors 1682 1682 {} 1683 1683 >>> f.clean_data 1684 1684 {'composers': [u'J'], 'name': u'Yesterday'} 1685 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']} )1685 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']}, auto_id=False) 1686 1686 >>> f.errors 1687 1687 {} … … 1704 1704 ... raise ValidationError(u'Please make sure your passwords match.') 1705 1705 ... return self.clean_data['password2'] 1706 >>> f = UserRegistration( )1706 >>> f = UserRegistration(auto_id=False) 1707 1707 >>> f.errors 1708 1708 {} 1709 >>> f = UserRegistration({} )1709 >>> f = UserRegistration({}, auto_id=False) 1710 1710 >>> f.errors 1711 1711 {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 1712 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'} )1712 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) 1713 1713 >>> f.errors 1714 1714 {'password2': [u'Please make sure your passwords match.']} 1715 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'} )1715 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False) 1716 1716 >>> f.errors 1717 1717 {} … … 1734 1734 ... raise ValidationError(u'Please make sure your passwords match.') 1735 1735 ... return self.clean_data 1736 >>> f = UserRegistration( )1736 >>> f = UserRegistration(auto_id=False) 1737 1737 >>> f.errors 1738 1738 {} 1739 >>> f = UserRegistration({} )1739 >>> f = UserRegistration({}, auto_id=False) 1740 1740 >>> print f.as_table() 1741 1741 <tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> … … 1747 1747 >>> f.errors 1748 1748 {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 1749 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'} )1749 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) 1750 1750 >>> f.errors 1751 1751 {'__all__': [u'Please make sure your passwords match.']} … … 1760 1760 <li>Password1: <input type="password" name="password1" value="foo" /></li> 1761 1761 <li>Password2: <input type="password" name="password2" value="bar" /></li> 1762 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'} )1762 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False) 1763 1763 >>> f.errors 1764 1764 {} … … 1772 1772 ... first_name = CharField() 1773 1773 ... last_name = CharField() 1774 ... def __init__(self ):1775 ... super(Person, self).__init__( )1774 ... def __init__(self, *args, **kwargs): 1775 ... super(Person, self).__init__(*args, **kwargs) 1776 1776 ... self.fields['birthday'] = DateField() 1777 >>> p = Person( )1777 >>> p = Person(auto_id=False) 1778 1778 >>> print p 1779 1779 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> … … 1790 1790 ... hidden_text = CharField(widget=HiddenInput) 1791 1791 ... birthday = DateField() 1792 >>> p = Person( )1792 >>> p = Person(auto_id=False) 1793 1793 >>> print p 1794 1794 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> … … 1823 1823 prepended. This message is displayed at the top of the output, regardless of 1824 1824 its field's order in the form. 1825 >>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'} )1825 >>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False) 1826 1826 >>> print p 1827 1827 <tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr> … … 1844 1844 ... foo = CharField(widget=HiddenInput) 1845 1845 ... bar = CharField(widget=HiddenInput) 1846 >>> p = TestForm( )1846 >>> p = TestForm(auto_id=False) 1847 1847 >>> print p.as_table() 1848 1848 <input type="hidden" name="foo" /><input type="hidden" name="bar" /> … … 1868 1868 ... field13 = CharField() 1869 1869 ... field14 = CharField() 1870 >>> p = TestForm( )1870 >>> p = TestForm(auto_id=False) 1871 1871 >>> print p 1872 1872 <tr><td>Field1:</td><td><input type="text" name="field1" /></td></tr> … … 1894 1894 ... realname = CharField(max_length=10, widget=TextInput) # redundantly define widget, just to test 1895 1895 ... address = CharField() # no max_length defined here 1896 >>> p = UserRegistration( )1896 >>> p = UserRegistration(auto_id=False) 1897 1897 >>> print p.as_ul() 1898 1898 <li>Username: <input type="text" name="username" maxlength="10" /></li> … … 1907 1907 ... username = CharField(max_length=10, widget=TextInput(attrs={'maxlength': 20})) 1908 1908 ... password = CharField(max_length=10, widget=PasswordInput) 1909 >>> p = UserRegistration( )1909 >>> p = UserRegistration(auto_id=False) 1910 1910 >>> print p.as_ul() 1911 1911 <li>Username: <input type="text" name="username" maxlength="10" /></li> … … 1919 1919 ... password1 = CharField(widget=PasswordInput) 1920 1920 ... password2 = CharField(widget=PasswordInput, label='Password (again)') 1921 >>> p = UserRegistration( )1921 >>> p = UserRegistration(auto_id=False) 1922 1922 >>> print p.as_ul() 1923 1923 <li>Your username: <input type="text" name="username" maxlength="10" /></li> … … 1938 1938 >>> def my_function(method, post_data): 1939 1939 ... if method == 'POST': 1940 ... form = UserRegistration(post_data )1940 ... form = UserRegistration(post_data, auto_id=False) 1941 1941 ... else: 1942 ... form = UserRegistration( )1942 ... form = UserRegistration(auto_id=False) 1943 1943 ... if form.is_valid(): 1944 1944 ... return 'VALID: %r' % form.clean_data … … 1996 1996 ... <input type="submit" /> 1997 1997 ... </form>''') 1998 >>> print t.render(Context({'form': UserRegistration( )}))1998 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 1999 1999 <form action=""> 2000 2000 <p><label>Your username: <input type="text" name="username" maxlength="10" /></label></p> … … 2003 2003 <input type="submit" /> 2004 2004 </form> 2005 >>> print t.render(Context({'form': UserRegistration({'username': 'django'} )}))2005 >>> print t.render(Context({'form': UserRegistration({'username': 'django'}, auto_id=False)})) 2006 2006 <form action=""> 2007 2007 <p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p> … … 2021 2021 ... <input type="submit" /> 2022 2022 ... </form>''') 2023 >>> print t.render(Context({'form': UserRegistration( )}))2023 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 2024 2024 <form action=""> 2025 2025 <p><label>Username: <input type="text" name="username" maxlength="10" /></label></p> … … 2039 2039 ... <input type="submit" /> 2040 2040 ... </form>''') 2041 >>> print t.render(Context({'form': UserRegistration( )}))2041 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 2042 2042 <form action=""> 2043 2043 <p>Username: <input type="text" name="username" maxlength="10" /></p> … … 2064 2064 ... <input type="submit" /> 2065 2065 ... </form>''') 2066 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'} )}))2066 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 2067 2067 <form action=""> 2068 2068 <p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p> … … 2078 2078 ... <input type="submit" /> 2079 2079 ... </form>''') 2080 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'} )}))2080 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 2081 2081 <form action=""> 2082 2082 <ul class="errorlist"><li>Please make sure your passwords match.</li></ul>
