commit 2800d34f426b9d9ee5637990d95658cebddfe2f1
Author: Jakub Vysoky <kvbik@stone.(none)>
Date: Mon Oct 22 18:50:51 2007 +0200
required forms count field added into formsets
diff --git a/django/newforms/formsets.py b/django/newforms/formsets.py
index 56179a9..af336c7 100644
a
|
b
|
__all__ = ('BaseFormSet', 'formset_for_form', 'all_valid')
|
7 | 7 | |
8 | 8 | # special field names |
9 | 9 | FORM_COUNT_FIELD_NAME = 'COUNT' |
| 10 | REQUIRED_FORMS_COUNT_FIELD_NAME = 'REQUIRED' |
10 | 11 | ORDERING_FIELD_NAME = 'ORDER' |
11 | 12 | DELETION_FIELD_NAME = 'DELETE' |
12 | 13 | |
… |
… |
class ManagementForm(Form):
|
17 | 18 | increment the count field of this form as well. |
18 | 19 | """ |
19 | 20 | def __init__(self, *args, **kwargs): |
| 21 | self.base_fields[REQUIRED_FORMS_COUNT_FIELD_NAME] = IntegerField(widget=HiddenInput) |
20 | 22 | self.base_fields[FORM_COUNT_FIELD_NAME] = IntegerField(widget=HiddenInput) |
21 | 23 | super(ManagementForm, self).__init__(*args, **kwargs) |
22 | 24 | |
… |
… |
class BaseFormSet(object):
|
37 | 39 | self.management_form = ManagementForm(data, files, auto_id=self.auto_id, prefix=self.prefix) |
38 | 40 | if self.management_form.is_valid(): |
39 | 41 | self.total_forms = self.management_form.cleaned_data[FORM_COUNT_FIELD_NAME] |
40 | | self.required_forms = self.total_forms - self.num_extra |
41 | | self.change_form_count = self.total_forms - self.num_extra |
| 42 | self.required_forms = self.management_form.cleaned_data[REQUIRED_FORMS_COUNT_FIELD_NAME] |
| 43 | self.change_form_count = self.required_forms |
42 | 44 | else: |
43 | 45 | # not sure that ValidationError is the best thing to raise here |
44 | 46 | raise ValidationError('ManagementForm data is missing or has been tampered with') |
… |
… |
class BaseFormSet(object):
|
46 | 48 | self.change_form_count = len(initial) |
47 | 49 | self.required_forms = len(initial) |
48 | 50 | self.total_forms = self.required_forms + self.num_extra |
49 | | self.management_form = ManagementForm(initial={FORM_COUNT_FIELD_NAME: self.total_forms}, auto_id=self.auto_id, prefix=self.prefix) |
| 51 | initial = { |
| 52 | FORM_COUNT_FIELD_NAME: self.total_forms, |
| 53 | REQUIRED_FORMS_COUNT_FIELD_NAME: self.required_forms, |
| 54 | } |
| 55 | self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) |
50 | 56 | else: |
51 | 57 | self.change_form_count = 0 |
52 | 58 | self.required_forms = 0 |
53 | 59 | self.total_forms = self.num_extra |
54 | | self.management_form = ManagementForm(initial={FORM_COUNT_FIELD_NAME: self.total_forms}, auto_id=self.auto_id, prefix=self.prefix) |
| 60 | initial = { |
| 61 | FORM_COUNT_FIELD_NAME: self.total_forms, |
| 62 | REQUIRED_FORMS_COUNT_FIELD_NAME: self.required_forms, |
| 63 | } |
| 64 | self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) |
55 | 65 | |
56 | 66 | def _get_add_forms(self): |
57 | 67 | """Return a list of all the add forms in this ``FormSet``.""" |