Ticket #4975: label_colon_removal.patch
File label_colon_removal.patch, 90.3 KB (added by , 17 years ago) |
---|
-
django/newforms/forms.py
129 129 output.append(error_row % force_unicode(bf_errors)) 130 130 if bf.label: 131 131 label = escape(force_unicode(bf.label)) 132 # Only add a colon if the label does not end in punctuation.133 if label[-1] not in ':?.!':134 label += ':'135 132 label = bf.label_tag(label) or '' 136 133 else: 137 134 label = '' -
tests/modeltests/model_forms/models.py
80 80 >>> CategoryForm = form_for_model(Category) 81 81 >>> f = CategoryForm() 82 82 >>> print f 83 <tr><th><label for="id_name">Name :</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>84 <tr><th><label for="id_slug">Slug :</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>85 <tr><th><label for="id_url">The URL :</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>83 <tr><th><label for="id_name">Name</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr> 84 <tr><th><label for="id_slug">Slug</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr> 85 <tr><th><label for="id_url">The URL</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr> 86 86 >>> print f.as_ul() 87 <li><label for="id_name">Name :</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>88 <li><label for="id_slug">Slug :</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li>89 <li><label for="id_url">The URL :</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>87 <li><label for="id_name">Name</label> <input id="id_name" type="text" name="name" maxlength="20" /></li> 88 <li><label for="id_slug">Slug</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li> 89 <li><label for="id_url">The URL</label> <input id="id_url" type="text" name="url" maxlength="40" /></li> 90 90 >>> print f['name'] 91 91 <input id="id_name" type="text" name="name" maxlength="20" /> 92 92 93 93 >>> f = CategoryForm(auto_id=False) 94 94 >>> print f.as_ul() 95 <li>Name :<input type="text" name="name" maxlength="20" /></li>96 <li>Slug :<input type="text" name="slug" maxlength="20" /></li>97 <li>The URL :<input type="text" name="url" maxlength="40" /></li>95 <li>Name <input type="text" name="name" maxlength="20" /></li> 96 <li>Slug <input type="text" name="slug" maxlength="20" /></li> 97 <li>The URL <input type="text" name="url" maxlength="40" /></li> 98 98 99 99 >>> f = CategoryForm({'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'}) 100 100 >>> f.is_valid() … … 164 164 >>> ArticleForm = form_for_model(Article) 165 165 >>> f = ArticleForm(auto_id=False) 166 166 >>> print f 167 <tr><th>Headline :</th><td><input type="text" name="headline" maxlength="50" /></td></tr>168 <tr><th>Slug :</th><td><input type="text" name="slug" maxlength="50" /></td></tr>169 <tr><th>Pub date :</th><td><input type="text" name="pub_date" /></td></tr>170 <tr><th>Writer :</th><td><select name="writer">167 <tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr> 168 <tr><th>Slug</th><td><input type="text" name="slug" maxlength="50" /></td></tr> 169 <tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr> 170 <tr><th>Writer</th><td><select name="writer"> 171 171 <option value="" selected="selected">---------</option> 172 172 <option value="1">Mike Royko</option> 173 173 <option value="2">Bob Woodward</option> 174 174 </select></td></tr> 175 <tr><th>Article :</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>176 <tr><th>Status :</th><td><select name="status">175 <tr><th>Article</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr> 176 <tr><th>Status</th><td><select name="status"> 177 177 <option value="" selected="selected">---------</option> 178 178 <option value="1">Draft</option> 179 179 <option value="2">Pending</option> 180 180 <option value="3">Live</option> 181 181 </select></td></tr> 182 <tr><th>Categories :</th><td><select multiple="multiple" name="categories">182 <tr><th>Categories</th><td><select multiple="multiple" name="categories"> 183 183 <option value="1">Entertainment</option> 184 184 <option value="2">It's a test</option> 185 185 <option value="3">Third test</option> … … 194 194 >>> PartialArticleForm = form_for_model(Article, fields=('headline','pub_date')) 195 195 >>> f = PartialArticleForm(auto_id=False) 196 196 >>> print f 197 <tr><th>Headline :</th><td><input type="text" name="headline" maxlength="50" /></td></tr>198 <tr><th>Pub date :</th><td><input type="text" name="pub_date" /></td></tr>197 <tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr> 198 <tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr> 199 199 200 200 You can pass a custom Form class to form_for_model. Make sure it's a 201 201 subclass of BaseForm, not Form. … … 214 214 >>> RoykoForm = form_for_instance(w) 215 215 >>> f = RoykoForm(auto_id=False) 216 216 >>> print f 217 <tr><th>Name :</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>217 <tr><th>Name</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> 218 218 219 219 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 220 220 >>> art.save() … … 223 223 >>> TestArticleForm = form_for_instance(art) 224 224 >>> f = TestArticleForm(auto_id=False) 225 225 >>> print f.as_ul() 226 <li>Headline :<input type="text" name="headline" value="Test article" maxlength="50" /></li>227 <li>Slug :<input type="text" name="slug" value="test-article" maxlength="50" /></li>228 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>229 <li>Writer :<select name="writer">226 <li>Headline <input type="text" name="headline" value="Test article" maxlength="50" /></li> 227 <li>Slug <input type="text" name="slug" value="test-article" maxlength="50" /></li> 228 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 229 <li>Writer <select name="writer"> 230 230 <option value="">---------</option> 231 231 <option value="1" selected="selected">Mike Royko</option> 232 232 <option value="2">Bob Woodward</option> 233 233 </select></li> 234 <li>Article :<textarea rows="10" cols="40" name="article">Hello.</textarea></li>235 <li>Status :<select name="status">234 <li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 235 <li>Status <select name="status"> 236 236 <option value="" selected="selected">---------</option> 237 237 <option value="1">Draft</option> 238 238 <option value="2">Pending</option> 239 239 <option value="3">Live</option> 240 240 </select></li> 241 <li>Categories :<select multiple="multiple" name="categories">241 <li>Categories <select multiple="multiple" name="categories"> 242 242 <option value="1">Entertainment</option> 243 243 <option value="2">It's a test</option> 244 244 <option value="3">Third test</option> … … 258 258 >>> PartialArticleForm = form_for_instance(art, fields=('headline', 'slug', 'pub_date')) 259 259 >>> f = PartialArticleForm({'headline': u'New headline', 'slug': 'new-headline', 'pub_date': u'1988-01-04'}, auto_id=False) 260 260 >>> print f.as_ul() 261 <li>Headline :<input type="text" name="headline" value="New headline" maxlength="50" /></li>262 <li>Slug :<input type="text" name="slug" value="new-headline" maxlength="50" /></li>263 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>261 <li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li> 262 <li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li> 263 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 264 264 >>> f.is_valid() 265 265 True 266 266 >>> new_art = f.save() … … 279 279 >>> TestArticleForm = form_for_instance(new_art) 280 280 >>> f = TestArticleForm(auto_id=False) 281 281 >>> print f.as_ul() 282 <li>Headline :<input type="text" name="headline" value="New headline" maxlength="50" /></li>283 <li>Slug :<input type="text" name="slug" value="new-headline" maxlength="50" /></li>284 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>285 <li>Writer :<select name="writer">282 <li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li> 283 <li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li> 284 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 285 <li>Writer <select name="writer"> 286 286 <option value="">---------</option> 287 287 <option value="1" selected="selected">Mike Royko</option> 288 288 <option value="2">Bob Woodward</option> 289 289 </select></li> 290 <li>Article :<textarea rows="10" cols="40" name="article">Hello.</textarea></li>291 <li>Status :<select name="status">290 <li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 291 <li>Status <select name="status"> 292 292 <option value="" selected="selected">---------</option> 293 293 <option value="1">Draft</option> 294 294 <option value="2">Pending</option> 295 295 <option value="3">Live</option> 296 296 </select></li> 297 <li>Categories :<select multiple="multiple" name="categories">297 <li>Categories <select multiple="multiple" name="categories"> 298 298 <option value="1" selected="selected">Entertainment</option> 299 299 <option value="2">It's a test</option> 300 300 <option value="3">Third test</option> … … 387 387 >>> ArticleForm = form_for_model(Article) 388 388 >>> f = ArticleForm(auto_id=False) 389 389 >>> print f.as_ul() 390 <li>Headline :<input type="text" name="headline" maxlength="50" /></li>391 <li>Slug :<input type="text" name="slug" maxlength="50" /></li>392 <li>Pub date :<input type="text" name="pub_date" /></li>393 <li>Writer :<select name="writer">390 <li>Headline <input type="text" name="headline" maxlength="50" /></li> 391 <li>Slug <input type="text" name="slug" maxlength="50" /></li> 392 <li>Pub date <input type="text" name="pub_date" /></li> 393 <li>Writer <select name="writer"> 394 394 <option value="" selected="selected">---------</option> 395 395 <option value="1">Mike Royko</option> 396 396 <option value="2">Bob Woodward</option> 397 397 </select></li> 398 <li>Article :<textarea rows="10" cols="40" name="article"></textarea></li>399 <li>Status :<select name="status">398 <li>Article <textarea rows="10" cols="40" name="article"></textarea></li> 399 <li>Status <select name="status"> 400 400 <option value="" selected="selected">---------</option> 401 401 <option value="1">Draft</option> 402 402 <option value="2">Pending</option> 403 403 <option value="3">Live</option> 404 404 </select></li> 405 <li>Categories :<select multiple="multiple" name="categories">405 <li>Categories <select multiple="multiple" name="categories"> 406 406 <option value="1">Entertainment</option> 407 407 <option value="2">It's a test</option> 408 408 <option value="3">Third</option> … … 412 412 >>> Writer.objects.create(name='Carl Bernstein') 413 413 <Writer: Carl Bernstein> 414 414 >>> print f.as_ul() 415 <li>Headline :<input type="text" name="headline" maxlength="50" /></li>416 <li>Slug :<input type="text" name="slug" maxlength="50" /></li>417 <li>Pub date :<input type="text" name="pub_date" /></li>418 <li>Writer :<select name="writer">415 <li>Headline <input type="text" name="headline" maxlength="50" /></li> 416 <li>Slug <input type="text" name="slug" maxlength="50" /></li> 417 <li>Pub date <input type="text" name="pub_date" /></li> 418 <li>Writer <select name="writer"> 419 419 <option value="" selected="selected">---------</option> 420 420 <option value="1">Mike Royko</option> 421 421 <option value="2">Bob Woodward</option> 422 422 <option value="3">Carl Bernstein</option> 423 423 </select></li> 424 <li>Article :<textarea rows="10" cols="40" name="article"></textarea></li>425 <li>Status :<select name="status">424 <li>Article <textarea rows="10" cols="40" name="article"></textarea></li> 425 <li>Status <select name="status"> 426 426 <option value="" selected="selected">---------</option> 427 427 <option value="1">Draft</option> 428 428 <option value="2">Pending</option> 429 429 <option value="3">Live</option> 430 430 </select></li> 431 <li>Categories :<select multiple="multiple" name="categories">431 <li>Categories <select multiple="multiple" name="categories"> 432 432 <option value="1">Entertainment</option> 433 433 <option value="2">It's a test</option> 434 434 <option value="3">Third</option> -
tests/regressiontests/forms/tests.py
347 347 ... somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things])) 348 348 >>> f = SomeForm() 349 349 >>> f.as_table() 350 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'350 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' 351 351 >>> f.as_table() 352 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'352 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' 353 353 >>> f = SomeForm({'somechoice': 2}) 354 354 >>> f.as_table() 355 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'355 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>' 356 356 357 357 You can also pass 'choices' to the constructor: 358 358 >>> w = Select(choices=[(1, 1), (2, 2), (3, 3)]) … … 2048 2048 Last name Lennon 2049 2049 Birthday 1940-10-9 2050 2050 >>> print p 2051 <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>2052 <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>2053 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>2051 <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> 2052 <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> 2053 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr> 2054 2054 2055 2055 Empty dictionaries are valid, too. 2056 2056 >>> p = Person({}) … … 2065 2065 ... 2066 2066 AttributeError: 'Person' object has no attribute 'cleaned_data' 2067 2067 >>> print p 2068 <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>2069 <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>2070 <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>2068 <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> 2069 <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> 2070 <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> 2071 2071 >>> print p.as_table() 2072 <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>2073 <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>2074 <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>2072 <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> 2073 <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> 2074 <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> 2075 2075 >>> print p.as_ul() 2076 <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>2077 <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>2078 <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>2076 <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> 2077 <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> 2078 <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> 2079 2079 >>> print p.as_p() 2080 2080 <ul class="errorlist"><li>This field is required.</li></ul> 2081 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2081 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2082 2082 <ul class="errorlist"><li>This field is required.</li></ul> 2083 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2083 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2084 2084 <ul class="errorlist"><li>This field is required.</li></ul> 2085 <p><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></p>2085 <p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p> 2086 2086 2087 2087 If you don't pass any values to the Form's __init__(), or if you pass None, 2088 2088 the Form will be considered unbound and won't do any validation. Form.errors … … 2099 2099 ... 2100 2100 AttributeError: 'Person' object has no attribute 'cleaned_data' 2101 2101 >>> print p 2102 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2103 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2104 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>2102 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2103 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2104 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 2105 2105 >>> print p.as_table() 2106 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2107 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2108 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>2106 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2107 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2108 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 2109 2109 >>> print p.as_ul() 2110 <li><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></li>2111 <li><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></li>2112 <li><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></li>2110 <li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li> 2111 <li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li> 2112 <li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></li> 2113 2113 >>> print p.as_p() 2114 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2115 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2116 <p><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></p>2114 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2115 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2116 <p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p> 2117 2117 2118 2118 Unicode values are handled properly. 2119 2119 >>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) 2120 2120 >>> p.as_table() 2121 u'<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>\n<tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'2121 u'<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>\n<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>' 2122 2122 >>> p.as_ul() 2123 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>'2123 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>' 2124 2124 >>> p.as_p() 2125 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>'2125 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>' 2126 2126 2127 2127 >>> p = Person({'last_name': u'Lennon'}) 2128 2128 >>> p.errors … … 2200 2200 the human-readable labels for a field. 2201 2201 >>> p = Person(auto_id='%s_id') 2202 2202 >>> print p.as_table() 2203 <tr><th><label for="first_name_id">First name :</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>2204 <tr><th><label for="last_name_id">Last name :</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>2205 <tr><th><label for="birthday_id">Birthday :</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>2203 <tr><th><label for="first_name_id">First name</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr> 2204 <tr><th><label for="last_name_id">Last name</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr> 2205 <tr><th><label for="birthday_id">Birthday</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr> 2206 2206 >>> print p.as_ul() 2207 <li><label for="first_name_id">First name :</label> <input type="text" name="first_name" id="first_name_id" /></li>2208 <li><label for="last_name_id">Last name :</label> <input type="text" name="last_name" id="last_name_id" /></li>2209 <li><label for="birthday_id">Birthday :</label> <input type="text" name="birthday" id="birthday_id" /></li>2207 <li><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></li> 2208 <li><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></li> 2209 <li><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></li> 2210 2210 >>> print p.as_p() 2211 <p><label for="first_name_id">First name :</label> <input type="text" name="first_name" id="first_name_id" /></p>2212 <p><label for="last_name_id">Last name :</label> <input type="text" name="last_name" id="last_name_id" /></p>2213 <p><label for="birthday_id">Birthday :</label> <input type="text" name="birthday" id="birthday_id" /></p>2211 <p><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></p> 2212 <p><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></p> 2213 <p><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></p> 2214 2214 2215 2215 If auto_id is any True value whose str() does not contain '%s', the "id" 2216 2216 attribute will be the name of the field. 2217 2217 >>> p = Person(auto_id=True) 2218 2218 >>> print p.as_ul() 2219 <li><label for="first_name">First name :</label> <input type="text" name="first_name" id="first_name" /></li>2220 <li><label for="last_name">Last name :</label> <input type="text" name="last_name" id="last_name" /></li>2221 <li><label for="birthday">Birthday :</label> <input type="text" name="birthday" id="birthday" /></li>2219 <li><label for="first_name">First name</label> <input type="text" name="first_name" id="first_name" /></li> 2220 <li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li> 2221 <li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li> 2222 2222 2223 2223 If auto_id is any False value, an "id" attribute won't be output unless it 2224 2224 was manually entered. 2225 2225 >>> p = Person(auto_id=False) 2226 2226 >>> print p.as_ul() 2227 <li>First name :<input type="text" name="first_name" /></li>2228 <li>Last name :<input type="text" name="last_name" /></li>2229 <li>Birthday :<input type="text" name="birthday" /></li>2227 <li>First name <input type="text" name="first_name" /></li> 2228 <li>Last name <input type="text" name="last_name" /></li> 2229 <li>Birthday <input type="text" name="birthday" /></li> 2230 2230 2231 2231 In this example, auto_id is False, but the "id" attribute for the "first_name" 2232 2232 field is given. Also note that field gets a <label>, while the others don't. … … 2236 2236 ... birthday = DateField() 2237 2237 >>> p = PersonNew(auto_id=False) 2238 2238 >>> print p.as_ul() 2239 <li><label for="first_name_id">First name :</label> <input type="text" id="first_name_id" name="first_name" /></li>2240 <li>Last name :<input type="text" name="last_name" /></li>2241 <li>Birthday :<input type="text" name="birthday" /></li>2239 <li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li> 2240 <li>Last name <input type="text" name="last_name" /></li> 2241 <li>Birthday <input type="text" name="birthday" /></li> 2242 2242 2243 2243 If the "id" attribute is specified in the Form and auto_id is True, the "id" 2244 2244 attribute in the Form gets precedence. 2245 2245 >>> p = PersonNew(auto_id=True) 2246 2246 >>> print p.as_ul() 2247 <li><label for="first_name_id">First name :</label> <input type="text" id="first_name_id" name="first_name" /></li>2248 <li><label for="last_name">Last name :</label> <input type="text" name="last_name" id="last_name" /></li>2249 <li><label for="birthday">Birthday :</label> <input type="text" name="birthday" id="birthday" /></li>2247 <li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li> 2248 <li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li> 2249 <li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li> 2250 2250 2251 2251 >>> class SignupForm(Form): 2252 2252 ... email = EmailField() … … 2394 2394 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2395 2395 </ul> 2396 2396 >>> print f 2397 <tr><th>Name :</th><td><input type="text" name="name" /></td></tr>2398 <tr><th>Language :</th><td><ul>2397 <tr><th>Name</th><td><input type="text" name="name" /></td></tr> 2398 <tr><th>Language</th><td><ul> 2399 2399 <li><label><input type="radio" name="language" value="P" /> Python</label></li> 2400 2400 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2401 2401 </ul></td></tr> 2402 2402 >>> print f.as_ul() 2403 <li>Name :<input type="text" name="name" /></li>2404 <li>Language :<ul>2403 <li>Name <input type="text" name="name" /></li> 2404 <li>Language <ul> 2405 2405 <li><label><input type="radio" name="language" value="P" /> Python</label></li> 2406 2406 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2407 2407 </ul></li> … … 2420 2420 either as_table() or as_ul(), the label for the RadioSelect will point to the 2421 2421 ID of the *first* radio button. 2422 2422 >>> print f 2423 <tr><th><label for="id_name">Name :</label></th><td><input type="text" name="name" id="id_name" /></td></tr>2424 <tr><th><label for="id_language_0">Language :</label></th><td><ul>2423 <tr><th><label for="id_name">Name</label></th><td><input type="text" name="name" id="id_name" /></td></tr> 2424 <tr><th><label for="id_language_0">Language</label></th><td><ul> 2425 2425 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2426 2426 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2427 2427 </ul></td></tr> 2428 2428 >>> print f.as_ul() 2429 <li><label for="id_name">Name :</label> <input type="text" name="name" id="id_name" /></li>2430 <li><label for="id_language_0">Language :</label> <ul>2429 <li><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></li> 2430 <li><label for="id_language_0">Language</label> <ul> 2431 2431 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2432 2432 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2433 2433 </ul></li> 2434 2434 >>> print f.as_p() 2435 <p><label for="id_name">Name :</label> <input type="text" name="name" id="id_name" /></p>2436 <p><label for="id_language_0">Language :</label> <ul>2435 <p><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></p> 2436 <p><label for="id_language_0">Language</label> <ul> 2437 2437 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2438 2438 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2439 2439 </ul></p> … … 2531 2531 ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=MultipleHiddenInput) 2532 2532 >>> f = SongFormHidden(MultiValueDict(dict(name=['Yesterday'], composers=['J', 'P'])), auto_id=False) 2533 2533 >>> print f.as_ul() 2534 <li>Name :<input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />2534 <li>Name <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" /> 2535 2535 <input type="hidden" name="composers" value="P" /></li> 2536 2536 2537 2537 When using CheckboxSelectMultiple, the framework expects a list of input and … … 2558 2558 2559 2559 >>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False) 2560 2560 >>> print f 2561 <tr><th>Special name :</th><td><ul class="errorlist"><li>Something's wrong with 'Nothing to escape'</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>2561 <tr><th>Special name</th><td><ul class="errorlist"><li>Something's wrong with 'Nothing to escape'</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr> 2562 2562 >>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}, auto_id=False) 2563 2563 >>> print f 2564 <tr><th>Special name :</th><td><ul class="errorlist"><li>Something's wrong with 'Should escape < & > and <script>alert('xss')</script>'</li></ul><input type="text" name="special_name" value="Should escape < & > and <script>alert('xss')</script>" /></td></tr>2564 <tr><th>Special name</th><td><ul class="errorlist"><li>Something's wrong with 'Should escape < & > and <script>alert('xss')</script>'</li></ul><input type="text" name="special_name" value="Should escape < & > and <script>alert('xss')</script>" /></td></tr> 2565 2565 2566 2566 # Validating multiple fields in relation to another ########################### 2567 2567 … … 2615 2615 {} 2616 2616 >>> f = UserRegistration({}, auto_id=False) 2617 2617 >>> print f.as_table() 2618 <tr><th>Username :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>2619 <tr><th>Password1 :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>2620 <tr><th>Password2 :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>2618 <tr><th>Username</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr> 2619 <tr><th>Password1</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr> 2620 <tr><th>Password2</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr> 2621 2621 >>> f.errors 2622 2622 {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 2623 2623 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) … … 2625 2625 {'__all__': [u'Please make sure your passwords match.']} 2626 2626 >>> print f.as_table() 2627 2627 <tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr> 2628 <tr><th>Username :</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>2629 <tr><th>Password1 :</th><td><input type="password" name="password1" value="foo" /></td></tr>2630 <tr><th>Password2 :</th><td><input type="password" name="password2" value="bar" /></td></tr>2628 <tr><th>Username</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr> 2629 <tr><th>Password1</th><td><input type="password" name="password1" value="foo" /></td></tr> 2630 <tr><th>Password2</th><td><input type="password" name="password2" value="bar" /></td></tr> 2631 2631 >>> print f.as_ul() 2632 2632 <li><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></li> 2633 <li>Username :<input type="text" name="username" value="adrian" maxlength="10" /></li>2634 <li>Password1 :<input type="password" name="password1" value="foo" /></li>2635 <li>Password2 :<input type="password" name="password2" value="bar" /></li>2633 <li>Username <input type="text" name="username" value="adrian" maxlength="10" /></li> 2634 <li>Password1 <input type="password" name="password1" value="foo" /></li> 2635 <li>Password2 <input type="password" name="password2" value="bar" /></li> 2636 2636 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False) 2637 2637 >>> f.errors 2638 2638 {} … … 2652 2652 ... self.fields['birthday'] = DateField() 2653 2653 >>> p = Person(auto_id=False) 2654 2654 >>> print p 2655 <tr><th>First name :</th><td><input type="text" name="first_name" /></td></tr>2656 <tr><th>Last name :</th><td><input type="text" name="last_name" /></td></tr>2657 <tr><th>Birthday :</th><td><input type="text" name="birthday" /></td></tr>2655 <tr><th>First name</th><td><input type="text" name="first_name" /></td></tr> 2656 <tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr> 2657 <tr><th>Birthday</th><td><input type="text" name="birthday" /></td></tr> 2658 2658 2659 2659 Instances of a dynamic Form do not persist fields from one Form instance to 2660 2660 the next. … … 2666 2666 >>> field_list = [('field1', CharField()), ('field2', CharField())] 2667 2667 >>> my_form = MyForm(field_list=field_list) 2668 2668 >>> print my_form 2669 <tr><th>Field1 :</th><td><input type="text" name="field1" /></td></tr>2670 <tr><th>Field2 :</th><td><input type="text" name="field2" /></td></tr>2669 <tr><th>Field1</th><td><input type="text" name="field1" /></td></tr> 2670 <tr><th>Field2</th><td><input type="text" name="field2" /></td></tr> 2671 2671 >>> field_list = [('field3', CharField()), ('field4', CharField())] 2672 2672 >>> my_form = MyForm(field_list=field_list) 2673 2673 >>> print my_form 2674 <tr><th>Field3 :</th><td><input type="text" name="field3" /></td></tr>2675 <tr><th>Field4 :</th><td><input type="text" name="field4" /></td></tr>2674 <tr><th>Field3</th><td><input type="text" name="field3" /></td></tr> 2675 <tr><th>Field4</th><td><input type="text" name="field4" /></td></tr> 2676 2676 2677 2677 >>> class MyForm(Form): 2678 2678 ... default_field_1 = CharField() … … 2684 2684 >>> field_list = [('field1', CharField()), ('field2', CharField())] 2685 2685 >>> my_form = MyForm(field_list=field_list) 2686 2686 >>> print my_form 2687 <tr><th>Default field 1 :</th><td><input type="text" name="default_field_1" /></td></tr>2688 <tr><th>Default field 2 :</th><td><input type="text" name="default_field_2" /></td></tr>2689 <tr><th>Field1 :</th><td><input type="text" name="field1" /></td></tr>2690 <tr><th>Field2 :</th><td><input type="text" name="field2" /></td></tr>2687 <tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr> 2688 <tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr> 2689 <tr><th>Field1</th><td><input type="text" name="field1" /></td></tr> 2690 <tr><th>Field2</th><td><input type="text" name="field2" /></td></tr> 2691 2691 >>> field_list = [('field3', CharField()), ('field4', CharField())] 2692 2692 >>> my_form = MyForm(field_list=field_list) 2693 2693 >>> print my_form 2694 <tr><th>Default field 1 :</th><td><input type="text" name="default_field_1" /></td></tr>2695 <tr><th>Default field 2 :</th><td><input type="text" name="default_field_2" /></td></tr>2696 <tr><th>Field3 :</th><td><input type="text" name="field3" /></td></tr>2697 <tr><th>Field4 :</th><td><input type="text" name="field4" /></td></tr>2694 <tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr> 2695 <tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr> 2696 <tr><th>Field3</th><td><input type="text" name="field3" /></td></tr> 2697 <tr><th>Field4</th><td><input type="text" name="field4" /></td></tr> 2698 2698 2699 2699 Similarly, changes to field attributes do not persist from one Form instance 2700 2700 to the next. … … 2752 2752 ... birthday = DateField() 2753 2753 >>> p = Person(auto_id=False) 2754 2754 >>> print p 2755 <tr><th>First name :</th><td><input type="text" name="first_name" /></td></tr>2756 <tr><th>Last name :</th><td><input type="text" name="last_name" /></td></tr>2757 <tr><th>Birthday :</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>2755 <tr><th>First name</th><td><input type="text" name="first_name" /></td></tr> 2756 <tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr> 2757 <tr><th>Birthday</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr> 2758 2758 >>> print p.as_ul() 2759 <li>First name :<input type="text" name="first_name" /></li>2760 <li>Last name :<input type="text" name="last_name" /></li>2761 <li>Birthday :<input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>2759 <li>First name <input type="text" name="first_name" /></li> 2760 <li>Last name <input type="text" name="last_name" /></li> 2761 <li>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li> 2762 2762 >>> print p.as_p() 2763 <p>First name :<input type="text" name="first_name" /></p>2764 <p>Last name :<input type="text" name="last_name" /></p>2765 <p>Birthday :<input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>2763 <p>First name <input type="text" name="first_name" /></p> 2764 <p>Last name <input type="text" name="last_name" /></p> 2765 <p>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p> 2766 2766 2767 2767 With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label. 2768 2768 >>> p = Person(auto_id='id_%s') 2769 2769 >>> print p 2770 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2771 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2772 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>2770 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2771 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2772 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr> 2773 2773 >>> print p.as_ul() 2774 <li><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></li>2775 <li><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></li>2776 <li><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>2774 <li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li> 2775 <li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li> 2776 <li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li> 2777 2777 >>> print p.as_p() 2778 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2779 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2780 <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>2778 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2779 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2780 <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> 2781 2781 2782 2782 If a field with a HiddenInput has errors, the as_table() and as_ul() output 2783 2783 will include the error message(s) with the text "(Hidden field [fieldname]) " … … 2786 2786 >>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False) 2787 2787 >>> print p 2788 2788 <tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr> 2789 <tr><th>First name :</th><td><input type="text" name="first_name" value="John" /></td></tr>2790 <tr><th>Last name :</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>2791 <tr><th>Birthday :</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>2789 <tr><th>First name</th><td><input type="text" name="first_name" value="John" /></td></tr> 2790 <tr><th>Last name</th><td><input type="text" name="last_name" value="Lennon" /></td></tr> 2791 <tr><th>Birthday</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr> 2792 2792 >>> print p.as_ul() 2793 2793 <li><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></li> 2794 <li>First name :<input type="text" name="first_name" value="John" /></li>2795 <li>Last name :<input type="text" name="last_name" value="Lennon" /></li>2796 <li>Birthday :<input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>2794 <li>First name <input type="text" name="first_name" value="John" /></li> 2795 <li>Last name <input type="text" name="last_name" value="Lennon" /></li> 2796 <li>Birthday <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li> 2797 2797 >>> print p.as_p() 2798 2798 <ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul> 2799 <p>First name :<input type="text" name="first_name" value="John" /></p>2800 <p>Last name :<input type="text" name="last_name" value="Lennon" /></p>2801 <p>Birthday :<input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>2799 <p>First name <input type="text" name="first_name" value="John" /></p> 2800 <p>Last name <input type="text" name="last_name" value="Lennon" /></p> 2801 <p>Birthday <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p> 2802 2802 2803 2803 A corner case: It's possible for a form to have only HiddenInputs. 2804 2804 >>> class TestForm(Form): … … 2830 2830 ... field14 = CharField() 2831 2831 >>> p = TestForm(auto_id=False) 2832 2832 >>> print p 2833 <tr><th>Field1 :</th><td><input type="text" name="field1" /></td></tr>2834 <tr><th>Field2 :</th><td><input type="text" name="field2" /></td></tr>2835 <tr><th>Field3 :</th><td><input type="text" name="field3" /></td></tr>2836 <tr><th>Field4 :</th><td><input type="text" name="field4" /></td></tr>2837 <tr><th>Field5 :</th><td><input type="text" name="field5" /></td></tr>2838 <tr><th>Field6 :</th><td><input type="text" name="field6" /></td></tr>2839 <tr><th>Field7 :</th><td><input type="text" name="field7" /></td></tr>2840 <tr><th>Field8 :</th><td><input type="text" name="field8" /></td></tr>2841 <tr><th>Field9 :</th><td><input type="text" name="field9" /></td></tr>2842 <tr><th>Field10 :</th><td><input type="text" name="field10" /></td></tr>2843 <tr><th>Field11 :</th><td><input type="text" name="field11" /></td></tr>2844 <tr><th>Field12 :</th><td><input type="text" name="field12" /></td></tr>2845 <tr><th>Field13 :</th><td><input type="text" name="field13" /></td></tr>2846 <tr><th>Field14 :</th><td><input type="text" name="field14" /></td></tr>2833 <tr><th>Field1</th><td><input type="text" name="field1" /></td></tr> 2834 <tr><th>Field2</th><td><input type="text" name="field2" /></td></tr> 2835 <tr><th>Field3</th><td><input type="text" name="field3" /></td></tr> 2836 <tr><th>Field4</th><td><input type="text" name="field4" /></td></tr> 2837 <tr><th>Field5</th><td><input type="text" name="field5" /></td></tr> 2838 <tr><th>Field6</th><td><input type="text" name="field6" /></td></tr> 2839 <tr><th>Field7</th><td><input type="text" name="field7" /></td></tr> 2840 <tr><th>Field8</th><td><input type="text" name="field8" /></td></tr> 2841 <tr><th>Field9</th><td><input type="text" name="field9" /></td></tr> 2842 <tr><th>Field10</th><td><input type="text" name="field10" /></td></tr> 2843 <tr><th>Field11</th><td><input type="text" name="field11" /></td></tr> 2844 <tr><th>Field12</th><td><input type="text" name="field12" /></td></tr> 2845 <tr><th>Field13</th><td><input type="text" name="field13" /></td></tr> 2846 <tr><th>Field14</th><td><input type="text" name="field14" /></td></tr> 2847 2847 2848 2848 Some Field classes have an effect on the HTML attributes of their associated 2849 2849 Widget. If you set max_length in a CharField and its associated widget is … … 2856 2856 ... address = CharField() # no max_length defined here 2857 2857 >>> p = UserRegistration(auto_id=False) 2858 2858 >>> print p.as_ul() 2859 <li>Username :<input type="text" name="username" maxlength="10" /></li>2860 <li>Password :<input type="password" name="password" maxlength="10" /></li>2861 <li>Realname :<input type="text" name="realname" maxlength="10" /></li>2862 <li>Address :<input type="text" name="address" /></li>2859 <li>Username <input type="text" name="username" maxlength="10" /></li> 2860 <li>Password <input type="password" name="password" maxlength="10" /></li> 2861 <li>Realname <input type="text" name="realname" maxlength="10" /></li> 2862 <li>Address <input type="text" name="address" /></li> 2863 2863 2864 2864 If you specify a custom "attrs" that includes the "maxlength" attribute, 2865 2865 the Field's max_length attribute will override whatever "maxlength" you specify … … 2869 2869 ... password = CharField(max_length=10, widget=PasswordInput) 2870 2870 >>> p = UserRegistration(auto_id=False) 2871 2871 >>> print p.as_ul() 2872 <li>Username :<input type="text" name="username" maxlength="10" /></li>2873 <li>Password :<input type="password" name="password" maxlength="10" /></li>2872 <li>Username <input type="text" name="username" maxlength="10" /></li> 2873 <li>Password <input type="password" name="password" maxlength="10" /></li> 2874 2874 2875 2875 # Specifying labels ########################################################### 2876 2876 … … 2883 2883 ... password2 = CharField(widget=PasswordInput, label='Password (again)') 2884 2884 >>> p = UserRegistration(auto_id=False) 2885 2885 >>> print p.as_ul() 2886 <li>Your username :<input type="text" name="username" maxlength="10" /></li>2887 <li>Password1 :<input type="password" name="password1" /></li>2888 <li>Password (again) :<input type="password" name="password2" /></li>2886 <li>Your username <input type="text" name="username" maxlength="10" /></li> 2887 <li>Password1 <input type="password" name="password1" /></li> 2888 <li>Password (again) <input type="password" name="password2" /></li> 2889 2889 2890 Labels for as_* methods will only end in a colon if they don't end in other2890 Labels for as_* methods will not add a colon to the label, regardless of the last character 2891 2891 punctuation already. 2892 2892 >>> class Questions(Form): 2893 2893 ... q1 = CharField(label='The first question') … … 2896 2896 ... q4 = CharField(label='Answer this question!') 2897 2897 ... q5 = CharField(label='The last question. Period.') 2898 2898 >>> print Questions(auto_id=False).as_p() 2899 <p>The first question :<input type="text" name="q1" /></p>2899 <p>The first question <input type="text" name="q1" /></p> 2900 2900 <p>What is your name? <input type="text" name="q2" /></p> 2901 2901 <p>The answer to life is: <input type="text" name="q3" /></p> 2902 2902 <p>Answer this question! <input type="text" name="q4" /></p> 2903 2903 <p>The last question. Period. <input type="text" name="q5" /></p> 2904 2904 >>> print Questions().as_p() 2905 <p><label for="id_q1">The first question :</label> <input type="text" name="q1" id="id_q1" /></p>2905 <p><label for="id_q1">The first question</label> <input type="text" name="q1" id="id_q1" /></p> 2906 2906 <p><label for="id_q2">What is your name?</label> <input type="text" name="q2" id="id_q2" /></p> 2907 2907 <p><label for="id_q3">The answer to life is:</label> <input type="text" name="q3" id="id_q3" /></p> 2908 2908 <p><label for="id_q4">Answer this question!</label> <input type="text" name="q4" id="id_q4" /></p> … … 2914 2914 ... password = CharField(widget=PasswordInput, label=u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111') 2915 2915 >>> p = UserRegistration(auto_id=False) 2916 2916 >>> p.as_ul() 2917 u'<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111 : <input type="text" name="username" maxlength="10" /></li>\n<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111:<input type="password" name="password" /></li>'2917 u'<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111 <input type="text" name="username" maxlength="10" /></li>\n<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111 <input type="password" name="password" /></li>' 2918 2918 2919 2919 If a label is set to the empty string for a field, that field won't get a label. 2920 2920 >>> class UserRegistration(Form): … … 2923 2923 >>> p = UserRegistration(auto_id=False) 2924 2924 >>> print p.as_ul() 2925 2925 <li> <input type="text" name="username" maxlength="10" /></li> 2926 <li>Password :<input type="password" name="password" /></li>2926 <li>Password <input type="password" name="password" /></li> 2927 2927 >>> p = UserRegistration(auto_id='id_%s') 2928 2928 >>> print p.as_ul() 2929 2929 <li> <input id="id_username" type="text" name="username" maxlength="10" /></li> 2930 <li><label for="id_password">Password :</label> <input type="password" name="password" id="id_password" /></li>2930 <li><label for="id_password">Password</label> <input type="password" name="password" id="id_password" /></li> 2931 2931 2932 2932 If label is None, Django will auto-create the label from the field name. This 2933 2933 is default behavior. … … 2936 2936 ... password = CharField(widget=PasswordInput) 2937 2937 >>> p = UserRegistration(auto_id=False) 2938 2938 >>> print p.as_ul() 2939 <li>Username :<input type="text" name="username" maxlength="10" /></li>2940 <li>Password :<input type="password" name="password" /></li>2939 <li>Username <input type="text" name="username" maxlength="10" /></li> 2940 <li>Password <input type="password" name="password" /></li> 2941 2941 >>> p = UserRegistration(auto_id='id_%s') 2942 2942 >>> print p.as_ul() 2943 <li><label for="id_username">Username :</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>2944 <li><label for="id_password">Password :</label> <input type="password" name="password" id="id_password" /></li>2943 <li><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></li> 2944 <li><label for="id_password">Password</label> <input type="password" name="password" id="id_password" /></li> 2945 2945 2946 2946 # Initial data ################################################################ 2947 2947 … … 2957 2957 Here, we're not submitting any data, so the initial value will be displayed. 2958 2958 >>> p = UserRegistration(auto_id=False) 2959 2959 >>> print p.as_ul() 2960 <li>Username :<input type="text" name="username" value="django" maxlength="10" /></li>2961 <li>Password :<input type="password" name="password" /></li>2960 <li>Username <input type="text" name="username" value="django" maxlength="10" /></li> 2961 <li>Password <input type="password" name="password" /></li> 2962 2962 2963 2963 Here, we're submitting data, so the initial value will *not* be displayed. 2964 2964 >>> p = UserRegistration({}, auto_id=False) 2965 2965 >>> print p.as_ul() 2966 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>2967 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>2966 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 2967 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 2968 2968 >>> p = UserRegistration({'username': u''}, auto_id=False) 2969 2969 >>> print p.as_ul() 2970 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>2971 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>2970 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 2971 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 2972 2972 >>> p = UserRegistration({'username': u'foo'}, auto_id=False) 2973 2973 >>> print p.as_ul() 2974 <li>Username :<input type="text" name="username" value="foo" maxlength="10" /></li>2975 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>2974 <li>Username <input type="text" name="username" value="foo" maxlength="10" /></li> 2975 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 2976 2976 2977 2977 An 'initial' value is *not* used as a fallback if data is not provided. In this 2978 2978 example, we don't provide a value for 'username', and the form raises a … … 2998 2998 Here, we're not submitting any data, so the initial value will be displayed. 2999 2999 >>> p = UserRegistration(initial={'username': 'django'}, auto_id=False) 3000 3000 >>> print p.as_ul() 3001 <li>Username :<input type="text" name="username" value="django" maxlength="10" /></li>3002 <li>Password :<input type="password" name="password" /></li>3001 <li>Username <input type="text" name="username" value="django" maxlength="10" /></li> 3002 <li>Password <input type="password" name="password" /></li> 3003 3003 >>> p = UserRegistration(initial={'username': 'stephane'}, auto_id=False) 3004 3004 >>> print p.as_ul() 3005 <li>Username :<input type="text" name="username" value="stephane" maxlength="10" /></li>3006 <li>Password :<input type="password" name="password" /></li>3005 <li>Username <input type="text" name="username" value="stephane" maxlength="10" /></li> 3006 <li>Password <input type="password" name="password" /></li> 3007 3007 3008 3008 The 'initial' parameter is meaningless if you pass data. 3009 3009 >>> p = UserRegistration({}, initial={'username': 'django'}, auto_id=False) 3010 3010 >>> print p.as_ul() 3011 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>3012 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3011 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 3012 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3013 3013 >>> p = UserRegistration({'username': u''}, initial={'username': 'django'}, auto_id=False) 3014 3014 >>> print p.as_ul() 3015 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>3016 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3015 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 3016 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3017 3017 >>> p = UserRegistration({'username': u'foo'}, initial={'username': 'django'}, auto_id=False) 3018 3018 >>> print p.as_ul() 3019 <li>Username :<input type="text" name="username" value="foo" maxlength="10" /></li>3020 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3019 <li>Username <input type="text" name="username" value="foo" maxlength="10" /></li> 3020 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3021 3021 3022 3022 A dynamic 'initial' value is *not* used as a fallback if data is not provided. 3023 3023 In this example, we don't provide a value for 'username', and the form raises a … … 3035 3035 ... password = CharField(widget=PasswordInput) 3036 3036 >>> p = UserRegistration(initial={'username': 'babik'}, auto_id=False) 3037 3037 >>> print p.as_ul() 3038 <li>Username :<input type="text" name="username" value="babik" maxlength="10" /></li>3039 <li>Password :<input type="password" name="password" /></li>3038 <li>Username <input type="text" name="username" value="babik" maxlength="10" /></li> 3039 <li>Password <input type="password" name="password" /></li> 3040 3040 3041 3041 # Callable initial data ######################################################## 3042 3042 … … 3056 3056 Here, we're not submitting any data, so the initial value will be displayed. 3057 3057 >>> p = UserRegistration(initial={'username': initial_django}, auto_id=False) 3058 3058 >>> print p.as_ul() 3059 <li>Username :<input type="text" name="username" value="django" maxlength="10" /></li>3060 <li>Password :<input type="password" name="password" /></li>3059 <li>Username <input type="text" name="username" value="django" maxlength="10" /></li> 3060 <li>Password <input type="password" name="password" /></li> 3061 3061 3062 3062 The 'initial' parameter is meaningless if you pass data. 3063 3063 >>> p = UserRegistration({}, initial={'username': initial_django}, auto_id=False) 3064 3064 >>> print p.as_ul() 3065 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>3066 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3065 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 3066 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3067 3067 >>> p = UserRegistration({'username': u''}, initial={'username': initial_django}, auto_id=False) 3068 3068 >>> print p.as_ul() 3069 <li><ul class="errorlist"><li>This field is required.</li></ul>Username :<input type="text" name="username" maxlength="10" /></li>3070 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3069 <li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li> 3070 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3071 3071 >>> p = UserRegistration({'username': u'foo'}, initial={'username': initial_django}, auto_id=False) 3072 3072 >>> print p.as_ul() 3073 <li>Username :<input type="text" name="username" value="foo" maxlength="10" /></li>3074 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /></li>3073 <li>Username <input type="text" name="username" value="foo" maxlength="10" /></li> 3074 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li> 3075 3075 3076 3076 A callable 'initial' value is *not* used as a fallback if data is not provided. 3077 3077 In this example, we don't provide a value for 'username', and the form raises a … … 3089 3089 ... password = CharField(widget=PasswordInput) 3090 3090 >>> p = UserRegistration(auto_id=False) 3091 3091 >>> print p.as_ul() 3092 <li>Username :<input type="text" name="username" value="django" maxlength="10" /></li>3093 <li>Password :<input type="password" name="password" /></li>3092 <li>Username <input type="text" name="username" value="django" maxlength="10" /></li> 3093 <li>Password <input type="password" name="password" /></li> 3094 3094 >>> p = UserRegistration(initial={'username': initial_stephane}, auto_id=False) 3095 3095 >>> print p.as_ul() 3096 <li>Username :<input type="text" name="username" value="stephane" maxlength="10" /></li>3097 <li>Password :<input type="password" name="password" /></li>3096 <li>Username <input type="text" name="username" value="stephane" maxlength="10" /></li> 3097 <li>Password <input type="password" name="password" /></li> 3098 3098 3099 3099 # Help text ################################################################### 3100 3100 … … 3105 3105 ... password = CharField(widget=PasswordInput, help_text='Choose wisely.') 3106 3106 >>> p = UserRegistration(auto_id=False) 3107 3107 >>> print p.as_ul() 3108 <li>Username :<input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>3109 <li>Password :<input type="password" name="password" /> Choose wisely.</li>3108 <li>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li> 3109 <li>Password <input type="password" name="password" /> Choose wisely.</li> 3110 3110 >>> print p.as_p() 3111 <p>Username :<input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>3112 <p>Password :<input type="password" name="password" /> Choose wisely.</p>3111 <p>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p> 3112 <p>Password <input type="password" name="password" /> Choose wisely.</p> 3113 3113 >>> print p.as_table() 3114 <tr><th>Username :</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr>3115 <tr><th>Password :</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr>3114 <tr><th>Username</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr> 3115 <tr><th>Password</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr> 3116 3116 3117 3117 The help text is displayed whether or not data is provided for the form. 3118 3118 >>> p = UserRegistration({'username': u'foo'}, auto_id=False) 3119 3119 >>> print p.as_ul() 3120 <li>Username :<input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>3121 <li><ul class="errorlist"><li>This field is required.</li></ul>Password :<input type="password" name="password" /> Choose wisely.</li>3120 <li>Username <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li> 3121 <li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /> Choose wisely.</li> 3122 3122 3123 3123 help_text is not displayed for hidden fields. It can be used for documentation 3124 3124 purposes, though. … … 3128 3128 ... next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination') 3129 3129 >>> p = UserRegistration(auto_id=False) 3130 3130 >>> print p.as_ul() 3131 <li>Username :<input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>3132 <li>Password :<input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>3131 <li>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li> 3132 <li>Password <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li> 3133 3133 3134 3134 Help text can include arbitrary Unicode characters. 3135 3135 >>> class UserRegistration(Form): 3136 3136 ... username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ') 3137 3137 >>> p = UserRegistration(auto_id=False) 3138 3138 >>> p.as_ul() 3139 u'<li>Username :<input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'3139 u'<li>Username <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>' 3140 3140 3141 3141 # Subclassing forms ########################################################### 3142 3142 … … 3151 3151 ... instrument = CharField() 3152 3152 >>> p = Person(auto_id=False) 3153 3153 >>> print p.as_ul() 3154 <li>First name :<input type="text" name="first_name" /></li>3155 <li>Last name :<input type="text" name="last_name" /></li>3156 <li>Birthday :<input type="text" name="birthday" /></li>3154 <li>First name <input type="text" name="first_name" /></li> 3155 <li>Last name <input type="text" name="last_name" /></li> 3156 <li>Birthday <input type="text" name="birthday" /></li> 3157 3157 >>> m = Musician(auto_id=False) 3158 3158 >>> print m.as_ul() 3159 <li>First name :<input type="text" name="first_name" /></li>3160 <li>Last name :<input type="text" name="last_name" /></li>3161 <li>Birthday :<input type="text" name="birthday" /></li>3162 <li>Instrument :<input type="text" name="instrument" /></li>3159 <li>First name <input type="text" name="first_name" /></li> 3160 <li>Last name <input type="text" name="last_name" /></li> 3161 <li>Birthday <input type="text" name="birthday" /></li> 3162 <li>Instrument <input type="text" name="instrument" /></li> 3163 3163 3164 3164 Yes, you can subclass multiple forms. The fields are added in the order in 3165 3165 which the parent classes are listed. … … 3173 3173 ... haircut_type = CharField() 3174 3174 >>> b = Beatle(auto_id=False) 3175 3175 >>> print b.as_ul() 3176 <li>First name :<input type="text" name="first_name" /></li>3177 <li>Last name :<input type="text" name="last_name" /></li>3178 <li>Birthday :<input type="text" name="birthday" /></li>3179 <li>Instrument :<input type="text" name="instrument" /></li>3180 <li>Haircut type :<input type="text" name="haircut_type" /></li>3176 <li>First name <input type="text" name="first_name" /></li> 3177 <li>Last name <input type="text" name="last_name" /></li> 3178 <li>Birthday <input type="text" name="birthday" /></li> 3179 <li>Instrument <input type="text" name="instrument" /></li> 3180 <li>Haircut type <input type="text" name="haircut_type" /></li> 3181 3181 3182 3182 # Forms with prefixes ######################################################### 3183 3183 … … 3199 3199 ... } 3200 3200 >>> p = Person(data, prefix='person1') 3201 3201 >>> print p.as_ul() 3202 <li><label for="id_person1-first_name">First name :</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li>3203 <li><label for="id_person1-last_name">Last name :</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li>3204 <li><label for="id_person1-birthday">Birthday :</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li>3202 <li><label for="id_person1-first_name">First name</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li> 3203 <li><label for="id_person1-last_name">Last name</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li> 3204 <li><label for="id_person1-birthday">Birthday</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li> 3205 3205 >>> print p['first_name'] 3206 3206 <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /> 3207 3207 >>> print p['last_name'] … … 3276 3276 ... return self.prefix and '%s-prefix-%s' % (self.prefix, field_name) or field_name 3277 3277 >>> p = Person(prefix='foo') 3278 3278 >>> print p.as_ul() 3279 <li><label for="id_foo-prefix-first_name">First name :</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li>3280 <li><label for="id_foo-prefix-last_name">Last name :</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li>3281 <li><label for="id_foo-prefix-birthday">Birthday :</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li>3279 <li><label for="id_foo-prefix-first_name">First name</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li> 3280 <li><label for="id_foo-prefix-last_name">Last name</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li> 3281 <li><label for="id_foo-prefix-birthday">Birthday</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li> 3282 3282 >>> data = { 3283 3283 ... 'foo-prefix-first_name': u'John', 3284 3284 ... 'foo-prefix-last_name': u'Lennon', … … 3350 3350 ... file1 = FileField() 3351 3351 >>> f = FileForm(auto_id=False) 3352 3352 >>> print f 3353 <tr><th>File1 :</th><td><input type="file" name="file1" /></td></tr>3353 <tr><th>File1</th><td><input type="file" name="file1" /></td></tr> 3354 3354 3355 3355 >>> f = FileForm(data={}, files={}, auto_id=False) 3356 3356 >>> print f 3357 <tr><th>File1 :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr>3357 <tr><th>File1</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr> 3358 3358 3359 3359 >>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':''}}, auto_id=False) 3360 3360 >>> print f 3361 <tr><th>File1 :</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr>3361 <tr><th>File1</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr> 3362 3362 3363 3363 >>> f = FileForm(data={}, files={'file1': 'something that is not a file'}, auto_id=False) 3364 3364 >>> print f 3365 <tr><th>File1 :</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr>3365 <tr><th>File1</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr> 3366 3366 3367 3367 >>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':'some content'}}, auto_id=False) 3368 3368 >>> print f 3369 <tr><th>File1 :</th><td><input type="file" name="file1" /></td></tr>3369 <tr><th>File1</th><td><input type="file" name="file1" /></td></tr> 3370 3370 >>> f.is_valid() 3371 3371 True 3372 3372 … … 3395 3395 >>> print my_function('GET', {}) 3396 3396 <form action="" method="post"> 3397 3397 <table> 3398 <tr><th>Username :</th><td><input type="text" name="username" maxlength="10" /></td></tr>3399 <tr><th>Password1 :</th><td><input type="password" name="password1" /></td></tr>3400 <tr><th>Password2 :</th><td><input type="password" name="password2" /></td></tr>3398 <tr><th>Username</th><td><input type="text" name="username" maxlength="10" /></td></tr> 3399 <tr><th>Password1</th><td><input type="password" name="password1" /></td></tr> 3400 <tr><th>Password2</th><td><input type="password" name="password2" /></td></tr> 3401 3401 </table> 3402 3402 <input type="submit" /> 3403 3403 </form> … … 3407 3407 <form action="" method="post"> 3408 3408 <table> 3409 3409 <tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr> 3410 <tr><th>Username :</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters (it has 23).</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>3411 <tr><th>Password1 :</th><td><input type="password" name="password1" value="foo" /></td></tr>3412 <tr><th>Password2 :</th><td><input type="password" name="password2" value="bar" /></td></tr>3410 <tr><th>Username</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters (it has 23).</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr> 3411 <tr><th>Password1</th><td><input type="password" name="password1" value="foo" /></td></tr> 3412 <tr><th>Password2</th><td><input type="password" name="password2" value="bar" /></td></tr> 3413 3413 </table> 3414 3414 <input type="submit" /> 3415 3415 </form> … … 3435 3435 displaying all the errors, including any that might not be associated with a 3436 3436 particular field. 3437 3437 >>> t = Template('''<form action=""> 3438 ... {{ form.username.errors.as_ul }}<p><label>Your username :{{ form.username }}</label></p>3439 ... {{ form.password1.errors.as_ul }}<p><label>Password :{{ form.password1 }}</label></p>3440 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) :{{ form.password2 }}</label></p>3438 ... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p> 3439 ... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p> 3440 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p> 3441 3441 ... <input type="submit" /> 3442 3442 ... </form>''') 3443 3443 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 3444 3444 <form action=""> 3445 <p><label>Your username :<input type="text" name="username" maxlength="10" /></label></p>3446 <p><label>Password :<input type="password" name="password1" /></label></p>3447 <p><label>Password (again) :<input type="password" name="password2" /></label></p>3445 <p><label>Your username <input type="text" name="username" maxlength="10" /></label></p> 3446 <p><label>Password <input type="password" name="password1" /></label></p> 3447 <p><label>Password (again) <input type="password" name="password2" /></label></p> 3448 3448 <input type="submit" /> 3449 3449 </form> 3450 3450 >>> print t.render(Context({'form': UserRegistration({'username': 'django'}, auto_id=False)})) 3451 3451 <form action=""> 3452 <p><label>Your username :<input type="text" name="username" value="django" maxlength="10" /></label></p>3453 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password :<input type="password" name="password1" /></label></p>3454 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password (again) :<input type="password" name="password2" /></label></p>3452 <p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p> 3453 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password <input type="password" name="password1" /></label></p> 3454 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password (again) <input type="password" name="password2" /></label></p> 3455 3455 <input type="submit" /> 3456 3456 </form> 3457 3457 … … 3460 3460 'label', Django will use the field name with underscores converted to spaces, 3461 3461 and the initial letter capitalized. 3462 3462 >>> t = Template('''<form action=""> 3463 ... <p><label>{{ form.username.label }} :{{ form.username }}</label></p>3464 ... <p><label>{{ form.password1.label }} :{{ form.password1 }}</label></p>3465 ... <p><label>{{ form.password2.label }} :{{ form.password2 }}</label></p>3463 ... <p><label>{{ form.username.label }} {{ form.username }}</label></p> 3464 ... <p><label>{{ form.password1.label }} {{ form.password1 }}</label></p> 3465 ... <p><label>{{ form.password2.label }} {{ form.password2 }}</label></p> 3466 3466 ... <input type="submit" /> 3467 3467 ... </form>''') 3468 3468 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 3469 3469 <form action=""> 3470 <p><label>Username :<input type="text" name="username" maxlength="10" /></label></p>3471 <p><label>Password1 :<input type="password" name="password1" /></label></p>3472 <p><label>Password2 :<input type="password" name="password2" /></label></p>3470 <p><label>Username <input type="text" name="username" maxlength="10" /></label></p> 3471 <p><label>Password1 <input type="password" name="password1" /></label></p> 3472 <p><label>Password2 <input type="password" name="password2" /></label></p> 3473 3473 <input type="submit" /> 3474 3474 </form> 3475 3475 … … 3478 3478 Recall from above that passing the "auto_id" argument to a Form gives each 3479 3479 field an "id" attribute. 3480 3480 >>> t = Template('''<form action=""> 3481 ... <p>{{ form.username.label_tag }} :{{ form.username }}</p>3482 ... <p>{{ form.password1.label_tag }} :{{ form.password1 }}</p>3483 ... <p>{{ form.password2.label_tag }} :{{ form.password2 }}</p>3481 ... <p>{{ form.username.label_tag }} {{ form.username }}</p> 3482 ... <p>{{ form.password1.label_tag }} {{ form.password1 }}</p> 3483 ... <p>{{ form.password2.label_tag }} {{ form.password2 }}</p> 3484 3484 ... <input type="submit" /> 3485 3485 ... </form>''') 3486 3486 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 3487 3487 <form action=""> 3488 <p>Username :<input type="text" name="username" maxlength="10" /></p>3489 <p>Password1 :<input type="password" name="password1" /></p>3490 <p>Password2 :<input type="password" name="password2" /></p>3488 <p>Username <input type="text" name="username" maxlength="10" /></p> 3489 <p>Password1 <input type="password" name="password1" /></p> 3490 <p>Password2 <input type="password" name="password2" /></p> 3491 3491 <input type="submit" /> 3492 3492 </form> 3493 3493 >>> print t.render(Context({'form': UserRegistration(auto_id='id_%s')})) 3494 3494 <form action=""> 3495 <p><label for="id_username">Username</label> :<input id="id_username" type="text" name="username" maxlength="10" /></p>3496 <p><label for="id_password1">Password1</label> :<input type="password" name="password1" id="id_password1" /></p>3497 <p><label for="id_password2">Password2</label> :<input type="password" name="password2" id="id_password2" /></p>3495 <p><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 3496 <p><label for="id_password1">Password1</label> <input type="password" name="password1" id="id_password1" /></p> 3497 <p><label for="id_password2">Password2</label> <input type="password" name="password2" id="id_password2" /></p> 3498 3498 <input type="submit" /> 3499 3499 </form> 3500 3500 3501 3501 User form.[field].help_text to output a field's help text. If the given field 3502 3502 does not have help text, nothing will be output. 3503 3503 >>> t = Template('''<form action=""> 3504 ... <p>{{ form.username.label_tag }} :{{ form.username }}<br />{{ form.username.help_text }}</p>3505 ... <p>{{ form.password1.label_tag }} :{{ form.password1 }}</p>3506 ... <p>{{ form.password2.label_tag }} :{{ form.password2 }}</p>3504 ... <p>{{ form.username.label_tag }} {{ form.username }}<br />{{ form.username.help_text }}</p> 3505 ... <p>{{ form.password1.label_tag }} {{ form.password1 }}</p> 3506 ... <p>{{ form.password2.label_tag }} {{ form.password2 }}</p> 3507 3507 ... <input type="submit" /> 3508 3508 ... </form>''') 3509 3509 >>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 3510 3510 <form action=""> 3511 <p>Username :<input type="text" name="username" maxlength="10" /><br />Good luck picking a username that doesn't already exist.</p>3512 <p>Password1 :<input type="password" name="password1" /></p>3513 <p>Password2 :<input type="password" name="password2" /></p>3511 <p>Username <input type="text" name="username" maxlength="10" /><br />Good luck picking a username that doesn't already exist.</p> 3512 <p>Password1 <input type="password" name="password1" /></p> 3513 <p>Password2 <input type="password" name="password2" /></p> 3514 3514 <input type="submit" /> 3515 3515 </form> 3516 3516 >>> Template('{{ form.password1.help_text }}').render(Context({'form': UserRegistration(auto_id=False)})) … … 3530 3530 template. If used on its own, it is displayed as a <ul> (or an empty string, if 3531 3531 the list of errors is empty). You can also use it in {% if %} statements. 3532 3532 >>> t = Template('''<form action=""> 3533 ... {{ form.username.errors.as_ul }}<p><label>Your username :{{ form.username }}</label></p>3534 ... {{ form.password1.errors.as_ul }}<p><label>Password :{{ form.password1 }}</label></p>3535 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) :{{ form.password2 }}</label></p>3533 ... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p> 3534 ... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p> 3535 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p> 3536 3536 ... <input type="submit" /> 3537 3537 ... </form>''') 3538 3538 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 3539 3539 <form action=""> 3540 <p><label>Your username :<input type="text" name="username" value="django" maxlength="10" /></label></p>3541 <p><label>Password :<input type="password" name="password1" value="foo" /></label></p>3542 <p><label>Password (again) :<input type="password" name="password2" value="bar" /></label></p>3540 <p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p> 3541 <p><label>Password <input type="password" name="password1" value="foo" /></label></p> 3542 <p><label>Password (again) <input type="password" name="password2" value="bar" /></label></p> 3543 3543 <input type="submit" /> 3544 3544 </form> 3545 3545 >>> t = Template('''<form action=""> 3546 3546 ... {{ form.non_field_errors }} 3547 ... {{ form.username.errors.as_ul }}<p><label>Your username :{{ form.username }}</label></p>3548 ... {{ form.password1.errors.as_ul }}<p><label>Password :{{ form.password1 }}</label></p>3549 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) :{{ form.password2 }}</label></p>3547 ... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p> 3548 ... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p> 3549 ... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p> 3550 3550 ... <input type="submit" /> 3551 3551 ... </form>''') 3552 3552 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 3553 3553 <form action=""> 3554 3554 <ul class="errorlist"><li>Please make sure your passwords match.</li></ul> 3555 <p><label>Your username :<input type="text" name="username" value="django" maxlength="10" /></label></p>3556 <p><label>Password :<input type="password" name="password1" value="foo" /></label></p>3557 <p><label>Password (again) :<input type="password" name="password2" value="bar" /></label></p>3555 <p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p> 3556 <p><label>Password <input type="password" name="password1" value="foo" /></label></p> 3557 <p><label>Password (again) <input type="password" name="password2" value="bar" /></label></p> 3558 3558 <input type="submit" /> 3559 3559 </form> 3560 3560 … … 3780 3780 ... field1 = ComplexField(widget=w) 3781 3781 >>> f = ComplexFieldForm() 3782 3782 >>> print f 3783 <tr><th><label for="id_field1_0">Field1 :</label></th><td><input type="text" name="field1_0" id="id_field1_0" />3783 <tr><th><label for="id_field1_0">Field1</label></th><td><input type="text" name="field1_0" id="id_field1_0" /> 3784 3784 <select multiple="multiple" name="field1_1" id="id_field1_1"> 3785 3785 <option value="J">John</option> 3786 3786 <option value="P">Paul</option> … … 3791 3791 3792 3792 >>> f = ComplexFieldForm({'field1_0':'some text','field1_1':['J','P'], 'field1_2_0':'2007-04-25', 'field1_2_1':'06:24:00'}) 3793 3793 >>> print f 3794 <tr><th><label for="id_field1_0">Field1 :</label></th><td><input type="text" name="field1_0" value="some text" id="id_field1_0" />3794 <tr><th><label for="id_field1_0">Field1</label></th><td><input type="text" name="field1_0" value="some text" id="id_field1_0" /> 3795 3795 <select multiple="multiple" name="field1_1" id="id_field1_1"> 3796 3796 <option value="J" selected="selected">John</option> 3797 3797 <option value="P" selected="selected">Paul</option> … … 3864 3864 >>> data = dict(email='invalid') 3865 3865 >>> f = CommentForm(data, auto_id=False, error_class=DivErrorList) 3866 3866 >>> print f.as_p() 3867 <p>Name :<input type="text" name="name" maxlength="50" /></p>3867 <p>Name <input type="text" name="name" maxlength="50" /></p> 3868 3868 <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> 3869 <p>Email :<input type="text" name="email" value="invalid" /></p>3869 <p>Email <input type="text" name="email" value="invalid" /></p> 3870 3870 <div class="errorlist"><div class="error">This field is required.</div></div> 3871 <p>Comment :<input type="text" name="comment" /></p>3871 <p>Comment <input type="text" name="comment" /></p> 3872 3872 3873 3873 ################################# 3874 3874 # Test multipart-encoded form # -
tests/regressiontests/forms/regressions.py
9 9 ... f1 = CharField(max_length=10, widget=TextInput(attrs=extra_attrs)) 10 10 ... f2 = CharField(widget=TextInput(attrs=extra_attrs)) 11 11 >>> TestForm(auto_id=False).as_p() 12 u'<p>F1 : <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2:<input type="text" class="special" name="f2" /></p>'12 u'<p>F1 <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2 <input type="text" class="special" name="f2" /></p>' 13 13 14 14 ####################### 15 15 # Tests for form i18n # … … 21 21 ... username = CharField(max_length=10, label=ugettext_lazy('Username')) 22 22 >>> f = SomeForm() 23 23 >>> print f.as_p() 24 <p><label for="id_username">Username :</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>24 <p><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 25 25 26 26 Translations are done at rendering time, so multi-lingual apps can define forms 27 27 early and still send back the right translation. … … 29 29 # XFAIL 30 30 >>> activate('de') 31 31 >>> print f.as_p() 32 <p><label for="id_username">Benutzername :</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>32 <p><label for="id_username">Benutzername</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 33 33 >>> activate('pl') 34 34 >>> f.as_p() 35 u'<p><label for="id_username">Nazwa u\u017cytkownika :</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>'35 u'<p><label for="id_username">Nazwa u\u017cytkownika</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>' 36 36 >>> deactivate() 37 37 38 38 Unicode decoding problems... … … 41 41 ... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf') 42 42 >>> f = SomeForm() 43 43 >>> f.as_p() 44 u'<p><label for="id_somechoice_0">\xc5\xf8\xdf :</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'44 u'<p><label for="id_somechoice_0">\xc5\xf8\xdf</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>' 45 45 46 46 Testing choice validation with UTF-8 bytestrings as input (these are the 47 47 Russian abbreviations "мес." and "шт.". … … 57 57 >>> activate('ru') 58 58 >>> f = SomeForm({}) 59 59 >>> f.as_p() 60 u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf :</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'60 u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>' 61 61 >>> deactivate() 62 62 63 63 Deep copying translated text shouldn't raise an error