- Timestamp:
- 06/17/07 17:18:54 (2 years ago)
- Files:
-
- django/branches/per-object-permissions/tests/regressiontests/bug639 (copied) (copied from django/trunk/tests/regressiontests/bug639)
- django/branches/per-object-permissions/tests/regressiontests/bug639/__init__.py (copied) (copied from django/trunk/tests/regressiontests/bug639/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/bug639/models.py (copied) (copied from django/trunk/tests/regressiontests/bug639/models.py)
- django/branches/per-object-permissions/tests/regressiontests/bug639/test.jpg (copied) (copied from django/trunk/tests/regressiontests/bug639/test.jpg)
- django/branches/per-object-permissions/tests/regressiontests/bug639/tests.py (copied) (copied from django/trunk/tests/regressiontests/bug639/tests.py)
- django/branches/per-object-permissions/tests/regressiontests/cache/tests.py (modified) (1 diff)
- django/branches/per-object-permissions/tests/regressiontests/datastructures (copied) (copied from django/trunk/tests/regressiontests/datastructures)
- django/branches/per-object-permissions/tests/regressiontests/datastructures/__init__.py (copied) (copied from django/trunk/tests/regressiontests/datastructures/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/datastructures/models.py (copied) (copied from django/trunk/tests/regressiontests/datastructures/models.py)
- django/branches/per-object-permissions/tests/regressiontests/datastructures/tests.py (copied) (copied from django/trunk/tests/regressiontests/datastructures/tests.py)
- django/branches/per-object-permissions/tests/regressiontests/dateformat/tests.py (modified) (1 diff)
- django/branches/per-object-permissions/tests/regressiontests/defaultfilters/tests.py (modified) (7 diffs)
- django/branches/per-object-permissions/tests/regressiontests/dispatch (copied) (copied from django/trunk/tests/regressiontests/dispatch)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/__init__.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/models.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/models.py)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/tests (copied) (copied from django/trunk/tests/regressiontests/dispatch/tests)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/tests/__init__.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/tests/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/tests/test_dispatcher.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/tests/test_dispatcher.py)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/tests/test_robustapply.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/tests/test_robustapply.py)
- django/branches/per-object-permissions/tests/regressiontests/dispatch/tests/test_saferef.py (copied) (copied from django/trunk/tests/regressiontests/dispatch/tests/test_saferef.py)
- django/branches/per-object-permissions/tests/regressiontests/fixtures_regress (copied) (copied from django/trunk/tests/regressiontests/fixtures_regress)
- django/branches/per-object-permissions/tests/regressiontests/fixtures_regress/fixtures (copied) (copied from django/trunk/tests/regressiontests/fixtures_regress/fixtures)
- django/branches/per-object-permissions/tests/regressiontests/fixtures_regress/fixtures/sequence.json (copied) (copied from django/trunk/tests/regressiontests/fixtures_regress/fixtures/sequence.json)
- django/branches/per-object-permissions/tests/regressiontests/fixtures_regress/__init__.py (copied) (copied from django/trunk/tests/regressiontests/fixtures_regress/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/fixtures_regress/models.py (copied) (copied from django/trunk/tests/regressiontests/fixtures_regress/models.py)
- django/branches/per-object-permissions/tests/regressiontests/forms/localflavor.py (copied) (copied from django/trunk/tests/regressiontests/forms/localflavor.py)
- django/branches/per-object-permissions/tests/regressiontests/forms/regressions.py (copied) (copied from django/trunk/tests/regressiontests/forms/regressions.py)
- django/branches/per-object-permissions/tests/regressiontests/forms/tests.py (modified) (52 diffs)
- django/branches/per-object-permissions/tests/regressiontests/httpwrappers/tests.py (modified) (7 diffs)
- django/branches/per-object-permissions/tests/regressiontests/humanize (copied) (copied from django/trunk/tests/regressiontests/humanize)
- django/branches/per-object-permissions/tests/regressiontests/humanize/__init__.py (copied) (copied from django/trunk/tests/regressiontests/humanize/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/humanize/models.py (copied) (copied from django/trunk/tests/regressiontests/humanize/models.py)
- django/branches/per-object-permissions/tests/regressiontests/humanize/tests.py (copied) (copied from django/trunk/tests/regressiontests/humanize/tests.py)
- django/branches/per-object-permissions/tests/regressiontests/invalid_admin_options (copied) (copied from django/trunk/tests/regressiontests/invalid_admin_options)
- django/branches/per-object-permissions/tests/regressiontests/invalid_admin_options/__init__.py (copied) (copied from django/trunk/tests/regressiontests/invalid_admin_options/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/invalid_admin_options/models.py (copied) (copied from django/trunk/tests/regressiontests/invalid_admin_options/models.py)
- django/branches/per-object-permissions/tests/regressiontests/many_to_one_regress/models.py (modified) (2 diffs)
- django/branches/per-object-permissions/tests/regressiontests/markup (deleted)
- django/branches/per-object-permissions/tests/regressiontests/null_queries/models.py (modified) (1 diff)
- django/branches/per-object-permissions/tests/regressiontests/serializers_regress (copied) (copied from django/trunk/tests/regressiontests/serializers_regress)
- django/branches/per-object-permissions/tests/regressiontests/serializers_regress/__init__.py (copied) (copied from django/trunk/tests/regressiontests/serializers_regress/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/serializers_regress/models.py (copied) (copied from django/trunk/tests/regressiontests/serializers_regress/models.py)
- django/branches/per-object-permissions/tests/regressiontests/serializers_regress/tests.py (copied) (copied from django/trunk/tests/regressiontests/serializers_regress/tests.py)
- django/branches/per-object-permissions/tests/regressiontests/templates/tests.py (modified) (13 diffs)
- django/branches/per-object-permissions/tests/regressiontests/templates/urls.py (copied) (copied from django/trunk/tests/regressiontests/templates/urls.py)
- django/branches/per-object-permissions/tests/regressiontests/templates/views.py (copied) (copied from django/trunk/tests/regressiontests/templates/views.py)
- django/branches/per-object-permissions/tests/regressiontests/test_client_regress (copied) (copied from django/trunk/tests/regressiontests/test_client_regress)
- django/branches/per-object-permissions/tests/regressiontests/test_client_regress/__init__.py (copied) (copied from django/trunk/tests/regressiontests/test_client_regress/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/test_client_regress/models.py (copied) (copied from django/trunk/tests/regressiontests/test_client_regress/models.py)
- django/branches/per-object-permissions/tests/regressiontests/test_client_regress/urls.py (copied) (copied from django/trunk/tests/regressiontests/test_client_regress/urls.py)
- django/branches/per-object-permissions/tests/regressiontests/test_client_regress/views.py (copied) (copied from django/trunk/tests/regressiontests/test_client_regress/views.py)
- django/branches/per-object-permissions/tests/regressiontests/text (copied) (copied from django/trunk/tests/regressiontests/text)
- django/branches/per-object-permissions/tests/regressiontests/text/__init__.py (copied) (copied from django/trunk/tests/regressiontests/text/__init__.py)
- django/branches/per-object-permissions/tests/regressiontests/text/models.py (copied) (copied from django/trunk/tests/regressiontests/text/models.py)
- django/branches/per-object-permissions/tests/regressiontests/text/tests.py (copied) (copied from django/trunk/tests/regressiontests/text/tests.py)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/per-object-permissions/tests/regressiontests/cache/tests.py
r3669 r5488 47 47 self.assertEqual(cache.has_key("goodbye"), False) 48 48 49 def test_in(self): 50 cache.set("hello", "goodbye") 51 self.assertEqual("hello" in cache, True) 52 self.assertEqual("goodbye" in cache, False) 53 49 54 def test_data_types(self): 50 55 # test data types django/branches/per-object-permissions/tests/regressiontests/dateformat/tests.py
r3940 r5488 18 18 >>> format(my_birthday, 'M') 19 19 'Jul' 20 >>> format(my_birthday, 'b') 21 'jul' 20 22 >>> format(my_birthday, 'n') 21 23 '7' django/branches/per-object-permissions/tests/regressiontests/defaultfilters/tests.py
r3810 r5488 1 # -*- coding: utf-8 -*- 2 1 3 r""" 2 4 >>> floatformat(7.7) … … 12 14 >>> floatformat(0.0) 13 15 '0' 16 >>> floatformat(7.7,3) 17 '7.700' 18 >>> floatformat(6.000000,3) 19 '6.000' 20 >>> floatformat(13.1031,-3) 21 '13.103' 22 >>> floatformat(11.1197, -2) 23 '11.12' 24 >>> floatformat(11.0000, -2) 25 '11' 26 >>> floatformat(11.000001, -2) 27 '11.00' 28 >>> floatformat(8.2798, 3) 29 '8.280' 30 >>> floatformat('foo') 31 '' 32 >>> floatformat(13.1031, 'bar') 33 '13.1031' 34 >>> floatformat('foo', 'bar') 35 '' 14 36 15 37 >>> addslashes('"double quotes" and \'single quotes\'') … … 68 90 'A sentence with a few words in it' 69 91 92 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0) 93 '' 94 95 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 2) 96 '<p>one <a href="#">two ...</a></p>' 97 98 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 4) 99 '<p>one <a href="#">two - three <br>four ...</a></p>' 100 101 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 5) 102 '<p>one <a href="#">two - three <br>four</a> five</p>' 103 104 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100) 105 '<p>one <a href="#">two - three <br>four</a> five</p>' 70 106 71 107 >>> upper('Mixed case input') … … 78 114 >>> urlencode('jack & jill') 79 115 'jack%20%26%20jill' 116 >>> urlencode(1) 117 '1' 80 118 81 119 … … 98 136 "this is a long\nparagraph of\ntext that\nreally needs\nto be wrapped\nI'm afraid" 99 137 138 >>> wordwrap('this is a short paragraph of text.\n But this line should be indented',14) 139 'this is a\nshort\nparagraph of\ntext.\n But this\nline should be\nindented' 140 141 >>> wordwrap('this is a short paragraph of text.\n But this line should be indented',15) 142 'this is a short\nparagraph of\ntext.\n But this line\nshould be\nindented' 143 100 144 >>> ljust('test', 10) 101 145 'test ' … … 124 168 >>> escape('<some html & special characters > here') 125 169 '<some html & special characters > here' 170 171 >>> escape(u'<some html & special characters > here ĐÅ€£') 172 u'<some html & special characters > here \xc4\x90\xc3\x85\xe2\x82\xac\xc2\xa3' 126 173 127 174 >>> linebreaks('line 1') … … 353 400 '0800 3569377' 354 401 355 402 # Filters shouldn't break if passed non-strings 403 >>> addslashes(123) 404 '123' 405 >>> linenumbers(123) 406 '1. 123' 407 >>> lower(123) 408 '123' 409 >>> make_list(123) 410 ['1', '2', '3'] 411 >>> slugify(123) 412 '123' 413 >>> title(123) 414 '123' 415 >>> truncatewords(123, 2) 416 '123' 417 >>> upper(123) 418 '123' 419 >>> urlencode(123) 420 '123' 421 >>> urlize(123) 422 '123' 423 >>> urlizetrunc(123, 1) 424 '123' 425 >>> wordcount(123) 426 1 427 >>> wordwrap(123, 2) 428 '123' 429 >>> ljust('123', 4) 430 '123 ' 431 >>> rjust('123', 4) 432 ' 123' 433 >>> center('123', 5) 434 ' 123 ' 435 >>> center('123', 6) 436 ' 123 ' 437 >>> cut(123, '2') 438 '13' 439 >>> escape(123) 440 '123' 441 >>> linebreaks(123) 442 '<p>123</p>' 443 >>> linebreaksbr(123) 444 '123' 445 >>> removetags(123, 'a') 446 '123' 447 >>> striptags(123) 448 '123' 356 449 357 450 """ django/branches/per-object-permissions/tests/regressiontests/forms/tests.py
r4242 r5488 1 1 # -*- coding: utf-8 -*- 2 r""" 2 from localflavor import localflavor_tests 3 from regressions import regression_tests 4 5 form_tests = r""" 3 6 >>> from django.newforms import * 4 7 >>> import datetime 8 >>> import time 5 9 >>> import re 10 >>> try: 11 ... from decimal import Decimal 12 ... except ImportError: 13 ... from django.utils._decimal import Decimal 6 14 7 15 ########### … … 73 81 u'<input type="password" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />' 74 82 83 The render_value argument lets you specify whether the widget should render 84 its value. You may want to do this for security reasons. 85 >>> w = PasswordInput(render_value=True) 86 >>> w.render('email', 'secret') 87 u'<input type="password" name="email" value="secret" />' 88 >>> w = PasswordInput(render_value=False) 89 >>> w.render('email', '') 90 u'<input type="password" name="email" />' 91 >>> w.render('email', None) 92 u'<input type="password" name="email" />' 93 >>> w.render('email', 'secret') 94 u'<input type="password" name="email" />' 95 >>> w = PasswordInput(attrs={'class': 'fun'}, render_value=False) 96 >>> w.render('email', 'secret') 97 u'<input type="password" class="fun" name="email" />' 98 75 99 # HiddenInput Widget ############################################################ 76 100 … … 107 131 u'<input type="hidden" class="special" name="email" />' 108 132 133 # MultipleHiddenInput Widget ################################################## 134 135 >>> w = MultipleHiddenInput() 136 >>> w.render('email', []) 137 u'' 138 >>> w.render('email', None) 139 u'' 140 >>> w.render('email', ['test@example.com']) 141 u'<input type="hidden" name="email" value="test@example.com" />' 142 >>> w.render('email', ['some "quoted" & ampersanded value']) 143 u'<input type="hidden" name="email" value="some "quoted" & ampersanded value" />' 144 >>> w.render('email', ['test@example.com', 'foo@example.com']) 145 u'<input type="hidden" name="email" value="test@example.com" />\n<input type="hidden" name="email" value="foo@example.com" />' 146 >>> w.render('email', ['test@example.com'], attrs={'class': 'fun'}) 147 u'<input type="hidden" name="email" value="test@example.com" class="fun" />' 148 >>> w.render('email', ['test@example.com', 'foo@example.com'], attrs={'class': 'fun'}) 149 u'<input type="hidden" name="email" value="test@example.com" class="fun" />\n<input type="hidden" name="email" value="foo@example.com" class="fun" />' 150 151 You can also pass 'attrs' to the constructor: 152 >>> w = MultipleHiddenInput(attrs={'class': 'fun'}) 153 >>> w.render('email', []) 154 u'' 155 >>> w.render('email', ['foo@example.com']) 156 u'<input type="hidden" class="fun" value="foo@example.com" name="email" />' 157 >>> w.render('email', ['foo@example.com', 'test@example.com']) 158 u'<input type="hidden" class="fun" value="foo@example.com" name="email" />\n<input type="hidden" class="fun" value="test@example.com" name="email" />' 159 160 'attrs' passed to render() get precedence over those passed to the constructor: 161 >>> w = MultipleHiddenInput(attrs={'class': 'pretty'}) 162 >>> w.render('email', ['foo@example.com'], attrs={'class': 'special'}) 163 u'<input type="hidden" class="special" value="foo@example.com" name="email" />' 164 165 >>> w.render('email', ['ŠĐĆŽćžšđ'], attrs={'class': 'fun'}) 166 u'<input type="hidden" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />' 167 168 'attrs' passed to render() get precedence over those passed to the constructor: 169 >>> w = MultipleHiddenInput(attrs={'class': 'pretty'}) 170 >>> w.render('email', ['foo@example.com'], attrs={'class': 'special'}) 171 u'<input type="hidden" class="special" value="foo@example.com" name="email" />' 172 109 173 # FileInput Widget ############################################################ 110 174 … … 135 199 >>> w = Textarea() 136 200 >>> w.render('msg', '') 137 u'<textarea name="msg"></textarea>'201 u'<textarea rows="10" cols="40" name="msg"></textarea>' 138 202 >>> w.render('msg', None) 139 u'<textarea name="msg"></textarea>'203 u'<textarea rows="10" cols="40" name="msg"></textarea>' 140 204 >>> w.render('msg', 'value') 141 u'<textarea name="msg">value</textarea>'205 u'<textarea rows="10" cols="40" name="msg">value</textarea>' 142 206 >>> w.render('msg', 'some "quoted" & ampersanded value') 143 u'<textarea name="msg">some "quoted" & ampersanded value</textarea>'144 >>> w.render('msg', 'value', attrs={'class': 'pretty' })145 u'<textarea name="msg" class="pretty">value</textarea>'207 u'<textarea rows="10" cols="40" name="msg">some "quoted" & ampersanded value</textarea>' 208 >>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}) 209 u'<textarea class="pretty" rows="20" cols="40" name="msg">value</textarea>' 146 210 147 211 You can also pass 'attrs' to the constructor: 148 212 >>> w = Textarea(attrs={'class': 'pretty'}) 149 213 >>> w.render('msg', '') 150 u'<textarea class="pretty" name="msg"></textarea>'214 u'<textarea rows="10" cols="40" name="msg" class="pretty"></textarea>' 151 215 >>> w.render('msg', 'example') 152 u'<textarea class="pretty" name="msg">example</textarea>'216 u'<textarea rows="10" cols="40" name="msg" class="pretty">example</textarea>' 153 217 154 218 'attrs' passed to render() get precedence over those passed to the constructor: 155 219 >>> w = Textarea(attrs={'class': 'pretty'}) 156 220 >>> w.render('msg', '', attrs={'class': 'special'}) 157 u'<textarea class="special" name="msg"></textarea>'221 u'<textarea rows="10" cols="40" name="msg" class="special"></textarea>' 158 222 159 223 >>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 160 u'<textarea class="fun" name="msg">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'224 u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>' 161 225 162 226 # CheckboxInput Widget ######################################################## … … 263 327 264 328 The 'choices' argument can be any iterable: 329 >>> from itertools import chain 265 330 >>> def get_choices(): 266 331 ... for i in range(5): … … 274 339 <option value="4">4</option> 275 340 </select> 341 >>> things = ({'id': 1, 'name': 'And Boom'}, {'id': 2, 'name': 'One More Thing!'}) 342 >>> class SomeForm(Form): 343 ... somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things])) 344 >>> f = SomeForm() 345 >>> f.as_table() 346 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>' 347 >>> f.as_table() 348 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>' 349 >>> f = SomeForm({'somechoice': 2}) 350 >>> f.as_table() 351 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>' 276 352 277 353 You can also pass 'choices' to the constructor: … … 296 372 >>> w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) 297 373 u'<select name="email">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" selected="selected">\u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</option>\n<option value="\u0107\u017e\u0161\u0111">abc\u0107\u017e\u0161\u0111</option>\n</select>' 374 375 If choices is passed to the constructor and is a generator, it can be iterated 376 over multiple times without getting consumed: 377 >>> w = Select(choices=get_choices()) 378 >>> print w.render('num', 2) 379 <select name="num"> 380 <option value="0">0</option> 381 <option value="1">1</option> 382 <option value="2" selected="selected">2</option> 383 <option value="3">3</option> 384 <option value="4">4</option> 385 </select> 386 >>> print w.render('num', 3) 387 <select name="num"> 388 <option value="0">0</option> 389 <option value="1">1</option> 390 <option value="2">2</option> 391 <option value="3" selected="selected">3</option> 392 <option value="4">4</option> 393 </select> 394 395 # NullBooleanSelect Widget #################################################### 396 397 >>> w = NullBooleanSelect() 398 >>> print w.render('is_cool', True) 399 <select name="is_cool"> 400 <option value="1">Unknown</option> 401 <option value="2" selected="selected">Yes</option> 402 <option value="3">No</option> 403 </select> 404 >>> print w.render('is_cool', False) 405 <select name="is_cool"> 406 <option value="1">Unknown</option> 407 <option value="2">Yes</option> 408 <option value="3" selected="selected">No</option> 409 </select> 410 >>> print w.render('is_cool', None) 411 <select name="is_cool"> 412 <option value="1" selected="selected">Unknown</option> 413 <option value="2">Yes</option> 414 <option value="3">No</option> 415 </select> 416 >>> print w.render('is_cool', '2') 417 <select name="is_cool"> 418 <option value="1">Unknown</option> 419 <option value="2" selected="selected">Yes</option> 420 <option value="3">No</option> 421 </select> 422 >>> print w.render('is_cool', '3') 423 <select name="is_cool"> 424 <option value="1">Unknown</option> 425 <option value="2">Yes</option> 426 <option value="3" selected="selected">No</option> 427 </select> 298 428 299 429 # SelectMultiple Widget ####################################################### … … 528 658 False 529 659 >>> r[1].name, r[1].value, r[1].choice_value, r[1].choice_label 530 ('beatle', u'J', 'P','Paul')660 ('beatle', u'J', u'P', u'Paul') 531 661 >>> r[10] 532 662 Traceback (most recent call last): 533 663 ... 534 664 IndexError: list index out of range 665 666 # Unicode choices are correctly rendered as HTML 667 >>> w = RadioSelect() 668 >>> unicode(w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')])) 669 u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="radio" name="email" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>' 670 671 # Attributes provided at instantiation are passed to the constituent inputs 672 >>> w = RadioSelect(attrs={'id':'foo'}) 673 >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))) 674 <ul> 675 <li><label><input checked="checked" type="radio" id="foo_0" value="J" name="beatle" /> John</label></li> 676 <li><label><input type="radio" id="foo_1" value="P" name="beatle" /> Paul</label></li> 677 <li><label><input type="radio" id="foo_2" value="G" name="beatle" /> George</label></li> 678 <li><label><input type="radio" id="foo_3" value="R" name="beatle" /> Ringo</label></li> 679 </ul> 680 681 # Attributes provided at render-time are passed to the constituent inputs 682 >>> w = RadioSelect() 683 >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')), attrs={'id':'bar'}) 684 <ul> 685 <li><label><input checked="checked" type="radio" id="bar_0" value="J" name="beatle" /> John</label></li> 686 <li><label><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label></li> 687 <li><label><input type="radio" id="bar_2" value="G" name="beatle" /> George</label></li> 688 <li><label><input type="radio" id="bar_3" value="R" name="beatle" /> Ringo</label></li> 689 </ul> 535 690 536 691 # CheckboxSelectMultiple Widget ############################################### … … 641 796 u'<ul>\n<li><label><input type="checkbox" name="nums" value="1" /> 1</label></li>\n<li><label><input type="checkbox" name="nums" value="2" /> 2</label></li>\n<li><label><input type="checkbox" name="nums" value="3" /> 3</label></li>\n<li><label><input checked="checked" type="checkbox" name="nums" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="checkbox" name="nums" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>' 642 797 798 # MultiWidget ################################################################# 799 800 >>> class MyMultiWidget(MultiWidget): 801 ... def decompress(self, value): 802 ... if value: 803 ... return value.split('__') 804 ... return ['', ''] 805 ... def format_output(self, rendered_widgets): 806 ... return u'<br />'.join(rendered_widgets) 807 >>> w = MyMultiWidget(widgets=(TextInput(attrs={'class': 'big'}), TextInput(attrs={'class': 'small'}))) 808 >>> w.render('name', ['john', 'lennon']) 809 u'<input type="text" class="big" value="john" name="name_0" /><br /><input type="text" class="small" value="lennon" name="name_1" />' 810 >>> w.render('name', 'john__lennon') 811 u'<input type="text" class="big" value="john" name="name_0" /><br /><input type="text" class="small" value="lennon" name="name_1" />' 812 >>> w.render('name', 'john__lennon', attrs={'id':'foo'}) 813 u'<input id="foo_0" type="text" class="big" value="john" name="name_0" /><br /><input id="foo_1" type="text" class="small" value="lennon" name="name_1" />' 814 >>> w = MyMultiWidget(widgets=(TextInput(attrs={'class': 'big'}), TextInput(attrs={'class': 'small'})), attrs={'id': 'bar'}) 815 >>> w.render('name', ['john', 'lennon']) 816 u'<input id="bar_0" type="text" class="big" value="john" name="name_0" /><br /><input id="bar_1" type="text" class="small" value="lennon" name="name_1" />' 817 818 # SplitDateTimeWidget ######################################################### 819 820 >>> w = SplitDateTimeWidget() 821 >>> w.render('date', '') 822 u'<input type="text" name="date_0" /><input type="text" name="date_1" />' 823 >>> w.render('date', None) 824 u'<input type="text" name="date_0" /><input type="text" name="date_1" />' 825 >>> w.render('date', datetime.datetime(2006, 1, 10, 7, 30)) 826 u'<input type="text" name="date_0" value="2006-01-10" /><input type="text" name="date_1" value="07:30:00" />' 827 >>> w.render('date', [datetime.date(2006, 1, 10), datetime.time(7, 30)]) 828 u'<input type="text" name="date_0" value="2006-01-10" /><input type="text" name="date_1" value="07:30:00" />' 829 830 You can also pass 'attrs' to the constructor. In this case, the attrs will be 831 included on both widgets. 832 >>> w = SplitDateTimeWidget(attrs={'class': 'pretty'}) 833 >>> w.render('date', datetime.datetime(2006, 1, 10, 7, 30)) 834 u'<input type="text" class="pretty" value="2006-01-10" name="date_0" /><input type="text" class="pretty" value="07:30:00" name="date_1" />' 835 643 836 ########## 644 837 # Fields # … … 659 852 a form. By default, Django will use a "pretty" version of the form 660 853 field name, if the Field is part of a Form. 854 initial -- A value to use in this Field's initial display. This value is 855 *not* used as a fallback if data isn't given. 661 856 662 857 Other than that, the Field subclasses have class-specific options for … … 765 960 >>> f = IntegerField(required=False) 766 961 >>> f.clean('') 767 u'' 962 >>> repr(f.clean('')) 963 'None' 768 964 >>> f.clean(None) 769 u'' 965 >>> repr(f.clean(None)) 966 'None' 770 967 >>> f.clean('1') 771 968 1 … … 853 1050 ... 854 1051 ValidationError: [u'Ensure this value is less than or equal to 20.'] 1052 1053 # FloatField ################################################################## 1054 1055 >>> f = FloatField() 1056 >>> f.clean('') 1057 Traceback (most recent call last): 1058 ... 1059 ValidationError: [u'This field is required.'] 1060 >>> f.clean(None) 1061 Traceback (most recent call last): 1062 ... 1063 ValidationError: [u'This field is required.'] 1064 >>> f.clean('1') 1065 1.0 1066 >>> isinstance(f.clean('1'), float) 1067 True 1068 >>> f.clean('23') 1069 23.0 1070 >>> f.clean('3.14') 1071 3.1400000000000001 1072 >>> f.clean('a') 1073 Traceback (most recent call last): 1074 ... 1075 ValidationError: [u'Enter a number.'] 1076 >>> f.clean('1.0 ') 1077 1.0 1078 >>> f.clean(' 1.0') 1079 1.0 1080 >>> f.clean(' 1.0 ') 1081 1.0 1082 >>> f.clean('1.0a') 1083 Traceback (most recent call last): 1084 ... 1085 ValidationError: [u'Enter a number.'] 1086 1087 >>> f = FloatField(required=False) 1088 >>> f.clean('') 1089 1090 >>> f.clean(None) 1091 1092 >>> f.clean('1') 1093 1.0 1094 1095 FloatField accepts min_value and max_value just like IntegerField: 1096 >>> f = FloatField(max_value=1.5, min_value=0.5) 1097 1098 >>> f.clean('1.6') 1099 Traceback (most recent call last): 1100 ... 1101 ValidationError: [u'Ensure this value is less than or equal to 1.5.'] 1102 >>> f.clean('0.4') 1103 Traceback (most recent call last): 1104 ... 1105 ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] 1106 >>> f.clean('1.5') 1107 1.5 1108 >>> f.clean('0.5') 1109 0.5 1110 1111 # DecimalField ################################################################ 1112 1113 >>> f = DecimalField(max_digits=4, decimal_places=2) 1114 >>> f.clean('') 1115 Traceback (most recent call last): 1116 ... 1117 ValidationError: [u'This field is required.'] 1118 >>> f.clean(None) 1119 Traceback (most recent call last): 1120 ... 1121 ValidationError: [u'This field is required.'] 1122 >>> f.clean('1') 1123 Decimal("1") 1124 >>> isinstance(f.clean('1'), Decimal) 1125 True 1126 >>> f.clean('23') 1127 Decimal("23") 1128 >>> f.clean('3.14') 1129 Decimal("3.14") 1130 >>> f.clean('a') 1131 Traceback (most recent call last): 1132 ... 1133 ValidationError: [u'Enter a number.'] 1134 >>> f.clean('1.0 ') 1135 Decimal("1.0") 1136 >>> f.clean(' 1.0') 1137 Decimal("1.0") 1138 >>> f.clean(' 1.0 ') 1139 Decimal("1.0") 1140 >>> f.clean('1.0a') 1141 Traceback (most recent call last): 1142 ... 1143 ValidationError: [u'Enter a number.'] 1144 >>> f.clean('123.45') 1145 Traceback (most recent call last): 1146 ... 1147 ValidationError: [u'Ensure that there are no more than 4 digits in total.'] 1148 >>> f.clean('1.234') 1149 Traceback (most recent call last): 1150 ... 1151 ValidationError: [u'Ensure that there are no more than 2 decimal places.'] 1152 >>> f.clean('123.4') 1153 Traceback (most recent call last): 1154 ... 1155 ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] 1156 >>> f = DecimalField(max_digits=4, decimal_places=2, required=False) 1157 >>> f.clean('') 1158 1159 >>> f.clean(None) 1160 1161 >>> f.clean('1') 1162 Decimal("1") 1163 1164 DecimalField accepts min_value and max_value just like IntegerField: 1165 >>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) 1166 1167 >>> f.clean('1.6') 1168 Traceback (most recent call last): 1169 ... 1170 ValidationError: [u'Ensure this value is less than or equal to 1.5.'] 1171 >>> f.clean('0.4') 1172 Traceback (most recent call last): 1173 ... 1174 ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] 1175 >>> f.clean('1.5') 1176 Decimal("1.5") 1177 >>> f.clean('0.5') 1178 Decimal("0.5") 855 1179 856 1180 # DateField ################################################################### … … 1284 1608 ... 1285 1609 ValidationError: [u'This URL appears to be a broken link.'] 1286 1287 EmailField also access min_length and max_length parameters, for convenience. 1610 >>> f = URLField(verify_exists=True, required=False) 1611 >>> f.clean('') 1612 u'' 1613 >>> f.clean('http://www.google.com') # This will fail if there's no Internet connection 1614 u'http://www.google.com' 1615 1616 URLField also access min_length and max_length parameters, for convenience. 1288 1617 >>> f = URLField(min_length=15, max_length=20) 1289 1618 >>> f.clean('http://f.com') … … 1354 1683 Traceback (most recent call last): 1355 1684 ... 1356 ValidationError: [u'Select a valid choice. 3is not one of the available choices.']1685 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] 1357 1686 1358 1687 >>> f = ChoiceField(choices=[('1', '1'), ('2', '2')], required=False) … … 1368 1697 Traceback (most recent call last): 1369 1698 ... 1370 ValidationError: [u'Select a valid choice. 3is not one of the available choices.']1699 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] 1371 1700 1372 1701 >>> f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')]) … … 1376 1705 Traceback (most recent call last): 1377 1706 ... 1378 ValidationError: [u'Select a valid choice. John is not one of the available choices.'] 1707 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] 1708 1709 # NullBooleanField ############################################################ 1710 1711 >>> f = NullBooleanField() 1712 >>> f.clean('') 1713 >>> f.clean(True) 1714 True 1715 >>> f.clean(False) 1716 False 1717 >>> f.clean(None) 1718 >>> f.clean('1') 1719 >>> f.clean('2') 1720 >>> f.clean('3') 1721 >>> f.clean('hello') 1379 1722 1380 1723 # MultipleChoiceField ######################################################### … … 1484 1827 u'' 1485 1828 1829 # SplitDateTimeField ########################################################## 1830 1831 >>> f = SplitDateTimeField() 1832 >>> f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]) 1833 datetime.datetime(2006, 1, 10, 7, 30) 1834 >>> f.clean(None) 1835 Traceback (most recent call last): 1836 ... 1837 ValidationError: [u'This field is required.'] 1838 >>> f.clean('') 1839 Traceback (most recent call last): 1840 ... 1841 ValidationError: [u'This field is required.'] 1842 >>> f.clean('hello') 1843 Traceback (most recent call last): 1844 ... 1845 ValidationError: [u'Enter a list of values.'] 1846 >>> f.clean(['hello', 'there']) 1847 Traceback (most recent call last): 1848 ... 1849 ValidationError: [u'Enter a valid date.', u'Enter a valid time.'] 1850 >>> f.clean(['2006-01-10', 'there']) 1851 Traceback (most recent call last): 1852 ... 1853 ValidationError: [u'Enter a valid time.'] 1854 >>> f.clean(['hello', '07:30']) 1855 Traceback (most recent call last): 1856 ... 1857 ValidationError: [u'Enter a valid date.'] 1858 1859 >>> f = SplitDateTimeField(required=False) 1860 >>> f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]) 1861 datetime.datetime(2006, 1, 10, 7, 30) 1862 >>> f.clean(None) 1863 >>> f.clean('') 1864 >>> f.clean('hello') 1865 Traceback (most recent call last): 1866 ... 1867 ValidationError: [u'Enter a list of values.'] 1868 >>> f.clean(['hello', 'there']) 1869 Traceback (most recent call last): 1870 ... 1871 ValidationError: [u'Enter a valid date.', u'Enter a valid time.'] 1872 >>> f.clean(['2006-01-10', 'there']) 1873 Traceback (most recent call last): 1874 ... 1875 ValidationError: [u'Enter a valid time.'] 1876 >>> f.clean(['hello', '07:30']) 1877 Traceback (most recent call last): 1878 ... 1879 ValidationError: [u'Enter a valid date.'] 1880 1486 1881 ######### 1487 1882 # Forms # … … 1501 1896 Pass a dictionary to a Form's __init__(). 1502 1897 >>> p = Person({'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9'}) 1898 >>> p.is_bound 1899 True 1503 1900 >>> p.errors 1504 1901 {} … … 1509 1906 >>> p.errors.as_text() 1510 1907 u'' 1511 >>> p.clean _data1908 >>> p.cleaned_data 1512 1909 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 1513 1910 >>> print p['first_name'] … … 1539 1936 Empty dictionaries are valid, too. 1540 1937 >>> p = Person({}) 1938 >>> p.is_bound 1939 True 1541 1940 >>> p.errors 1542 1941 {'first_name': [u'This field is required.'], 'last_name': [u'This field is required.'], 'birthday': [u'This field is required.']} 1543 1942 >>> p.is_valid() 1544 1943 False 1944 >>> p.cleaned_data 1945 Traceback (most recent call last): 1946 ... 1947 AttributeError: 'Person' object has no attribute 'cleaned_data' 1545 1948 >>> print p 1546 1949 <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> … … 1564 1967 1565 1968 If you don't pass any values to the Form's __init__(), or if you pass None, 1566 the Form w on't do any validation. Form.errors will be an empty dictionary *but*1567 Form.is_valid() will return False.1969 the Form will be considered unbound and won't do any validation. Form.errors 1970 will be an empty dictionary *but* Form.is_valid() will return False. 1568 1971 >>> p = Person() 1972 >>> p.is_bound 1973 False 1569 1974 >>> p.errors 1570 1975 {} 1571 1976 >>> p.is_valid() 1572 1977 False 1978 >>> p.cleaned_data 1979 Traceback (most recent call last): 1980 ... 1981 AttributeError: 'Person' object has no attribute 'cleaned_data' 1573 1982 >>> print p 1574 1983 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> … … 1609 2018 * birthday 1610 2019 * This field is required. 1611 >>> p.clean_data 1612 >>> repr(p.clean_data) 1613 'None' 2020 >>> p.cleaned_data 2021 Traceback (most recent call last): 2022 ... 2023 AttributeError: 'Person' object has no attribute 'cleaned_data' 1614 2024 >>> p['first_name'].errors 1615 2025 [u'This field is required.'] … … 1626 2036 >>> print p['birthday'] 1
