diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
a
|
b
|
|
49 | 49 | True |
50 | 50 | >>> [form.cleaned_data for form in formset.forms] |
51 | 51 | [{'votes': 100, 'choice': u'Calexico'}] |
| 52 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 53 | [{'votes': 100, 'choice': u'Calexico'}] |
52 | 54 | |
53 | 55 | If a FormSet was not passed any data, its is_valid method should return False. |
54 | 56 | >>> formset = ChoiceFormSet() |
… |
… |
|
104 | 106 | True |
105 | 107 | >>> [form.cleaned_data for form in formset.forms] |
106 | 108 | [{'votes': 100, 'choice': u'Calexico'}, {}] |
| 109 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 110 | [{'votes': 100, 'choice': u'Calexico'}] |
107 | 111 | |
108 | 112 | But the second form was blank! Shouldn't we get some errors? No. If we display |
109 | 113 | a form as blank, it's ok for it to be submitted as blank. If we fill out even |
… |
… |
|
186 | 190 | True |
187 | 191 | >>> [form.cleaned_data for form in formset.forms] |
188 | 192 | [{}, {}, {}] |
| 193 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 194 | [] |
189 | 195 | |
190 | 196 | |
191 | 197 | We can just fill out one of the forms. |
… |
… |
|
207 | 213 | True |
208 | 214 | >>> [form.cleaned_data for form in formset.forms] |
209 | 215 | [{'votes': 100, 'choice': u'Calexico'}, {}, {}] |
| 216 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 217 | [{'votes': 100, 'choice': u'Calexico'}] |
210 | 218 | |
211 | 219 | |
212 | 220 | And once again, if we try to partially complete a form, validation will fail. |
… |
… |
|
299 | 307 | True |
300 | 308 | >>> [form.cleaned_data for form in formset.forms] |
301 | 309 | [{'votes': 100, 'DELETE': False, 'choice': u'Calexico'}, {'votes': 900, 'DELETE': True, 'choice': u'Fergie'}, {}] |
| 310 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 311 | [{'votes': 100, 'DELETE': False, 'choice': u'Calexico'}] |
302 | 312 | >>> [form.cleaned_data for form in formset.deleted_forms] |
303 | 313 | [{'votes': 900, 'DELETE': True, 'choice': u'Fergie'}] |
304 | 314 | |
… |
… |
|
328 | 338 | Traceback (most recent call last): |
329 | 339 | ... |
330 | 340 | AttributeError: 'CheckForm' object has no attribute 'cleaned_data' |
| 341 | >>> [form.cleaned_data for form in formset.valid_forms] |
| 342 | [{'field': 200, 'DELETE': False}] |
331 | 343 | |
332 | 344 | If we remove the deletion flag now we will have our validation back. |
333 | 345 | |
… |
… |
|
400 | 412 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
401 | 413 | >>> formset.is_valid() |
402 | 414 | True |
| 415 | >>> for form in formset.valid_forms: |
| 416 | ... print form.cleaned_data |
| 417 | {'votes': 500, 'ORDER': 0, 'choice': u'The Decemberists'} |
| 418 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
| 419 | {'votes': 900, 'ORDER': 2, 'choice': u'Fergie'} |
403 | 420 | >>> for form in formset.ordered_forms: |
404 | 421 | ... print form.cleaned_data |
405 | 422 | {'votes': 500, 'ORDER': 0, 'choice': u'The Decemberists'} |
… |
… |
|
430 | 447 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
431 | 448 | >>> formset.is_valid() |
432 | 449 | True |
| 450 | >>> for form in formset.valid_forms: |
| 451 | ... print form.cleaned_data |
| 452 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
| 453 | {'votes': 900, 'ORDER': 2, 'choice': u'Fergie'} |
| 454 | {'votes': 500, 'ORDER': None, 'choice': u'The Decemberists'} |
| 455 | {'votes': 50, 'ORDER': None, 'choice': u'Basia Bulat'} |
433 | 456 | >>> for form in formset.ordered_forms: |
434 | 457 | ... print form.cleaned_data |
435 | 458 | {'votes': 100, 'ORDER': 1, 'choice': u'Calexico'} |
… |
… |
|
448 | 471 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
449 | 472 | >>> formset.is_valid() |
450 | 473 | True |
| 474 | >>> for form in formset.valid_forms: |
| 475 | ... print form.cleaned_data |
451 | 476 | >>> for form in formset.ordered_forms: |
452 | 477 | ... print form.cleaned_data |
453 | 478 | |
… |
… |
|
509 | 534 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
510 | 535 | >>> formset.is_valid() |
511 | 536 | True |
| 537 | >>> for form in formset.valid_forms: |
| 538 | ... print form.cleaned_data |
| 539 | {'votes': 500, 'DELETE': False, 'ORDER': 0, 'choice': u'The Decemberists'} |
| 540 | {'votes': 100, 'DELETE': False, 'ORDER': 1, 'choice': u'Calexico'} |
512 | 541 | >>> for form in formset.ordered_forms: |
513 | 542 | ... print form.cleaned_data |
514 | 543 | {'votes': 500, 'DELETE': False, 'ORDER': 0, 'choice': u'The Decemberists'} |
… |
… |
|
542 | 571 | Traceback (most recent call last): |
543 | 572 | ... |
544 | 573 | AttributeError: 'Person' object has no attribute 'cleaned_data' |
| 574 | >>> [form.cleaned_data for form in p.valid_forms] |
| 575 | [{'DELETE': False, 'name': u'John Smith', 'ORDER': None}] |
545 | 576 | |
546 | 577 | # FormSet clean hook ########################################################## |
547 | 578 | |