1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #11801 -- Corrected form validation to ensure you can still get deleted_forms and ordered_forms when a form that is being deleted doesn't validate. Thanks to dantallis for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12771 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2010-03-12 15:51:00 +00:00
parent fbf00078e1
commit 4120a181e9
2 changed files with 52 additions and 9 deletions

View File

@@ -332,6 +332,26 @@ If we remove the deletion flag now we will have our validation back.
>>> formset.is_valid()
False
Should be able to get deleted_forms from a valid formset even if a
deleted form would have been invalid.
>>> class Person(Form):
... name = CharField()
>>> PeopleForm = formset_factory(
... form=Person,
... can_delete=True)
>>> p = PeopleForm(
... {'form-0-name': u'', 'form-0-DELETE': u'on', # no name!
... 'form-TOTAL_FORMS': 1, 'form-INITIAL_FORMS': 1,
... 'form-MAX_NUM_FORMS': 1})
>>> p.is_valid()
True
>>> len(p.deleted_forms)
1
# FormSets with ordering ######################################################
We can also add ordering ability to a FormSet with an agrument to
@@ -492,6 +512,26 @@ True
>>> [form.cleaned_data for form in formset.deleted_forms]
[{'votes': 900, 'DELETE': True, 'ORDER': 2, 'choice': u'Fergie'}]
Should be able to get ordered forms from a valid formset even if a
deleted form would have been invalid.
>>> class Person(Form):
... name = CharField()
>>> PeopleForm = formset_factory(
... form=Person,
... can_delete=True,
... can_order=True)
>>> p = PeopleForm(
... {'form-0-name': u'', 'form-0-DELETE': u'on', # no name!
... 'form-TOTAL_FORMS': 1, 'form-INITIAL_FORMS': 1,
... 'form-MAX_NUM_FORMS': 1})
>>> p.is_valid()
True
>>> p.ordered_forms
[]
# FormSet clean hook ##########################################################