# HG changeset patch
# Parent 1967de9eb7e9389fa57e3cd61c7f4e1f7d079f8a
diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
a
|
b
|
|
53 | 53 | True |
54 | 54 | >>> [form.cleaned_data for form in formset.forms] |
55 | 55 | [{'votes': 100, 'choice': u'Calexico'}] |
| 56 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 57 | [{'votes': 100, 'choice': u'Calexico'}] |
56 | 58 | |
57 | 59 | If a FormSet was not passed any data, its is_valid method should return False. |
58 | 60 | >>> formset = ChoiceFormSet() |
… |
… |
|
108 | 110 | True |
109 | 111 | >>> [form.cleaned_data for form in formset.forms] |
110 | 112 | [{'votes': 100, 'choice': u'Calexico'}, {}] |
| 113 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 114 | [{'votes': 100, 'choice': u'Calexico'}] |
111 | 115 | |
112 | 116 | But the second form was blank! Shouldn't we get some errors? No. If we display |
113 | 117 | a form as blank, it's ok for it to be submitted as blank. If we fill out even |
… |
… |
|
190 | 194 | True |
191 | 195 | >>> [form.cleaned_data for form in formset.forms] |
192 | 196 | [{}, {}, {}] |
| 197 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 198 | [] |
193 | 199 | |
194 | 200 | |
195 | 201 | We can just fill out one of the forms. |
… |
… |
|
211 | 217 | True |
212 | 218 | >>> [form.cleaned_data for form in formset.forms] |
213 | 219 | [{'votes': 100, 'choice': u'Calexico'}, {}, {}] |
| 220 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 221 | [{'votes': 100, 'choice': u'Calexico'}] |
214 | 222 | |
215 | 223 | |
216 | 224 | And once again, if we try to partially complete a form, validation will fail. |
… |
… |
|
303 | 311 | True |
304 | 312 | >>> [form.cleaned_data for form in formset.forms] |
305 | 313 | [{'votes': 100, 'DELETE': False, 'choice': u'Calexico'}, {'votes': 900, 'DELETE': True, 'choice': u'Fergie'}, {}] |
| 314 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 315 | [{'votes': 100, 'DELETE': False, 'choice': u'Calexico'}] |
306 | 316 | >>> [form.cleaned_data for form in formset.deleted_forms] |
307 | 317 | [{'votes': 900, 'DELETE': True, 'choice': u'Fergie'}] |
308 | 318 | |
… |
… |
|
332 | 342 | Traceback (most recent call last): |
333 | 343 | ... |
334 | 344 | AttributeError: 'CheckForm' object has no attribute 'cleaned_data' |
| 345 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 346 | [{'field': 200, 'DELETE': False}] |
335 | 347 | |
336 | 348 | If we remove the deletion flag now we will have our validation back. |
337 | 349 | |
… |
… |
|
404 | 416 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
405 | 417 | >>> formset.is_valid() |
406 | 418 | True |
| 419 | >>> for form in formset.valid_forms: |
| 420 | ... print form.cleaned_data |
| 421 | {'votes': 500, 'ORDER': 0, 'choice': u'The Decemberists'} |
| 422 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
| 423 | {'votes': 900, 'ORDER': 2, 'choice': u'Fergie'} |
407 | 424 | >>> for form in formset.ordered_forms: |
408 | 425 | ... print form.cleaned_data |
409 | 426 | {'votes': 500, 'ORDER': 0, 'choice': u'The Decemberists'} |
… |
… |
|
434 | 451 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
435 | 452 | >>> formset.is_valid() |
436 | 453 | True |
| 454 | >>> for form in formset.valid_forms: |
| 455 | ... print form.cleaned_data |
| 456 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
| 457 | {'votes': 900, 'ORDER': 2, 'choice': u'Fergie'} |
| 458 | {'votes': 500, 'ORDER': None, 'choice': u'The Decemberists'} |
| 459 | {'votes': 50, 'ORDER': None, 'choice': u'Basia Bulat'} |
437 | 460 | >>> for form in formset.ordered_forms: |
438 | 461 | ... print form.cleaned_data |
439 | 462 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
… |
… |
|
452 | 475 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
453 | 476 | >>> formset.is_valid() |
454 | 477 | True |
| 478 | >>> for form in formset.valid_forms: |
| 479 | ... print form.cleaned_data |
455 | 480 | >>> for form in formset.ordered_forms: |
456 | 481 | ... print form.cleaned_data |
457 | 482 | |
… |
… |
|
513 | 538 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
514 | 539 | >>> formset.is_valid() |
515 | 540 | True |
| 541 | >>> for form in formset.valid_forms: |
| 542 | ... print form.cleaned_data |
| 543 | {'votes': 500, 'DELETE': False, 'ORDER': 0, 'choice': u'The Decemberists'} |
| 544 | {'votes': 100, 'DELETE': False, 'ORDER': 1, 'choice': u'Calexico'} |
516 | 545 | >>> for form in formset.ordered_forms: |
517 | 546 | ... print form.cleaned_data |
518 | 547 | {'votes': 500, 'DELETE': False, 'ORDER': 0, 'choice': u'The Decemberists'} |
… |
… |
|
546 | 575 | Traceback (most recent call last): |
547 | 576 | ... |
548 | 577 | AttributeError: 'Person' object has no attribute 'cleaned_data' |
| 578 | >>> [form.cleaned_data for form in p.valid_forms] |
| 579 | [{'DELETE': False, 'name': u'John Smith', 'ORDER': None}] |
549 | 580 | |
550 | 581 | # FormSet clean hook ########################################################## |
551 | 582 | |