Ticket #5923: required-forms-count.diff

File required-forms-count.diff, 8.1 KB (added by James Turnbull <james@…>, 17 years ago)

Merged patch file that applies to nfa-trunk

  • django/newforms/formsets.py

     
    77
    88# special field names
    99FORM_COUNT_FIELD_NAME = 'COUNT'
     10REQUIRED_FORMS_COUNT_FIELD_NAME = 'REQUIRED'
    1011ORDERING_FIELD_NAME = 'ORDER'
    1112DELETION_FIELD_NAME = 'DELETE'
    1213
     
    1718    increment the count field of this form as well.
    1819    """
    1920    def __init__(self, *args, **kwargs):
     21        self.base_fields[REQUIRED_FORMS_COUNT_FIELD_NAME] = IntegerField(widget=HiddenInput)
    2022        self.base_fields[FORM_COUNT_FIELD_NAME] = IntegerField(widget=HiddenInput)
    2123        super(ManagementForm, self).__init__(*args, **kwargs)
    2224
     
    3739            self.management_form = ManagementForm(data, files, auto_id=self.auto_id, prefix=self.prefix)
    3840            if self.management_form.is_valid():
    3941                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
    4244            else:
    4345                # not sure that ValidationError is the best thing to raise here
    4446                raise ValidationError('ManagementForm data is missing or has been tampered with')
     
    4648            self.change_form_count = len(initial)
    4749            self.required_forms = len(initial)
    4850            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)
    5056        else:
    5157            self.change_form_count = 0
    5258            self.required_forms = 0
    5359            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)
    5565
    5666    def _get_add_forms(self):
    5767        """Return a list of all the add forms in this ``FormSet``."""
  • tests/modeltests/model_formsets/models.py

     
    3030
    3131>>> data = {
    3232...     'form-COUNT': '3',
     33...     'form-REQUIRED': '0', # number of forms filled before
    3334...     'form-0-name': 'Charles Baudelaire',
    3435...     'form-1-name': 'Arthur Rimbaud',
    3536...     'form-2-name': '',
     
    6667
    6768>>> data = {
    6869...     'form-COUNT': '3',
     70...     'form-REQUIRED': '2', # number of forms filled before
    6971...     'form-0-id': '2',
    7072...     'form-0-name': 'Arthur Rimbaud',
    7173...     'form-1-id': '1',
     
    107109
    108110>>> data = {
    109111...     'form-COUNT': '4',
     112...     'form-REQUIRED': '3', # number of forms filled before
    110113...     'form-0-id': '2',
    111114...     'form-0-name': 'Arthur Rimbaud',
    112115...     'form-1-id': '1',
     
    148151
    149152>>> data = {
    150153...     'book_set-COUNT': '3',
     154...     'book_set-REQUIRED': '0', # number of forms filled before
    151155...     'book_set-0-title': 'Les Fleurs du Mal',
    152156...     'book_set-1-title': '',
    153157...     'book_set-2-title': '',
     
    181185
    182186>>> data = {
    183187...     'book_set-COUNT': '3',
     188...     'book_set-REQUIRED': '1', # number of forms filled before
    184189...     'book_set-0-id': '1',
    185190...     'book_set-0-title': 'Les Fleurs du Mal',
    186191...     'book_set-1-title': 'Le Spleen de Paris',
  • tests/regressiontests/forms/formsets.py

     
    3333
    3434>>> data = {
    3535...     'choices-COUNT': '1', # the number of forms rendered
     36...     'choices-REQUIRED': '0', # number of forms filled before
    3637...     'choices-0-choice': 'Calexico',
    3738...     'choices-0-votes': '100',
    3839... }
     
    5859
    5960>>> data = {
    6061...     'choices-COUNT': '1', # the number of forms rendered
     62...     'choices-REQUIRED': '1', # number of forms filled before
     63...     'choices-REQUIRED': '0', # number of forms filled before
    6164...     'choices-0-choice': 'Calexico',
    6265...     'choices-0-votes': '',
    6366... }
     
    9497
    9598>>> data = {
    9699...     'choices-COUNT': '2', # the number of forms rendered
     100...     'choices-REQUIRED': '1', # number of forms filled before
    97101...     'choices-0-choice': 'Calexico',
    98102...     'choices-0-votes': '100',
    99103...     'choices-1-choice': '',
     
    114118
    115119>>> data = {
    116120...     'choices-COUNT': '2', # the number of forms rendered
     121...     'choices-REQUIRED': '1', # number of forms filled before
    117122...     'choices-0-choice': 'Calexico',
    118123...     'choices-0-votes': '100',
    119124...     'choices-1-choice': 'The Decemberists',
     
    133138
    134139>>> data = {
    135140...     'choices-COUNT': '2', # the number of forms rendered
     141...     'choices-REQUIRED': '1', # number of forms filled before
    136142...     'choices-0-choice': '', # deleted value
    137143...     'choices-0-votes': '', # deleted value
    138144...     'choices-1-choice': '',
     
    169175
    170176>>> data = {
    171177...     'choices-COUNT': '3', # the number of forms rendered
     178...     'choices-REQUIRED': '0', # number of forms filled before
    172179...     'choices-0-choice': '',
    173180...     'choices-0-votes': '',
    174181...     'choices-1-choice': '',
     
    188195
    189196>>> data = {
    190197...     'choices-COUNT': '3', # the number of forms rendered
     198...     'choices-REQUIRED': '0', # number of forms filled before
    191199...     'choices-0-choice': 'Calexico',
    192200...     'choices-0-votes': '100',
    193201...     'choices-1-choice': '',
     
    207215
    208216>>> data = {
    209217...     'choices-COUNT': '3', # the number of forms rendered
     218...     'choices-REQUIRED': '0', # number of forms filled before
    210219...     'choices-0-choice': 'Calexico',
    211220...     'choices-0-votes': '100',
    212221...     'choices-1-choice': 'The Decemberists',
     
    244253
    245254>>> data = {
    246255...     'choices-COUNT': '3', # the number of forms rendered
     256...     'choices-REQUIRED': '1', # number of forms filled before
    247257...     'choices-0-choice': 'Calexico',
    248258...     'choices-0-votes': '100',
    249259...     'choices-1-choice': '',
     
    289299
    290300>>> data = {
    291301...     'choices-COUNT': '3', # the number of forms rendered
     302...     'choices-REQUIRED': '2', # number of forms filled before
    292303...     'choices-0-choice': 'Calexico',
    293304...     'choices-0-votes': '100',
    294305...     'choices-0-DELETE': '',
     
    336347
    337348>>> data = {
    338349...     'choices-COUNT': '3', # the number of forms rendered
     350...     'choices-REQUIRED': '2', # number of forms filled before
    339351...     'choices-0-choice': 'Calexico',
    340352...     'choices-0-votes': '100',
    341353...     'choices-0-ORDER': '1',
     
    391403
    392404>>> data = {
    393405...     'choices-COUNT': '4', # the number of forms rendered
     406...     'choices-REQUIRED': '3', # number of forms filled before
    394407...     'choices-0-choice': 'Calexico',
    395408...     'choices-0-votes': '100',
    396409...     'choices-0-ORDER': '1',
     
    451464
    452465>>> data = {
    453466...     'drinks-COUNT': '2',
     467...     'drinks-REQUIRED': '0', # number of forms filled before
    454468...     'drinks-0-name': 'Gin and Tonic',
    455469...     'drinks-1-name': 'Gin and Tonic',
    456470... }
     
    471485
    472486>>> data = {
    473487...     'drinks-COUNT': '2',
     488...     'drinks-REQUIRED': '0', # number of forms filled before
    474489...     'drinks-0-name': 'Gin and Tonic',
    475490...     'drinks-1-name': 'Bloody Mary',
    476491... }
Back to Top