Django

Code

Changeset 8058

Show
Ignore:
Timestamp:
07/22/08 23:28:52 (5 months ago)
Author:
brosner
Message:

Made the semi-private _max_form_count live on the public API of formsets by renaming it to max_num. This also removes the ManagementForm? use of MAX_COUNT since that usage should just be referenced to the formset's max_num property. Refs #7899. Thanks Peter of the Norse for straightening me out.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/forms/formsets.py

    r8046 r8058  
    1111TOTAL_FORM_COUNT = 'TOTAL_FORMS' 
    1212INITIAL_FORM_COUNT = 'INITIAL_FORMS' 
    13 MAX_FORM_COUNT = 'MAX_FORMS' 
    1413ORDERING_FIELD_NAME = 'ORDER' 
    1514DELETION_FIELD_NAME = 'DELETE' 
     
    2423        self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    2524        self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    26         self.base_fields[MAX_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    2725        super(ManagementForm, self).__init__(*args, **kwargs) 
    2826 
     
    4846                self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT] 
    4947                self._initial_form_count = self.management_form.cleaned_data[INITIAL_FORM_COUNT] 
    50                 self._max_form_count = self.management_form.cleaned_data[MAX_FORM_COUNT] 
    5148            else: 
    5249                raise ValidationError('ManagementForm data is missing or has been tampered with') 
     
    5451            if initial: 
    5552                self._initial_form_count = len(initial) 
    56                 if self._initial_form_count > self._max_form_count and self._max_form_count > 0: 
    57                     self._initial_form_count = self._max_form_count 
     53                if self._initial_form_count > self.max_num and self.max_num > 0: 
     54                    self._initial_form_count = self.max_num 
    5855                self._total_form_count = self._initial_form_count + self.extra 
    5956            else: 
    6057                self._initial_form_count = 0 
    6158                self._total_form_count = self.extra 
    62             if self._total_form_count > self._max_form_count and self._max_form_count > 0: 
    63                 self._total_form_count = self._max_form_count 
     59            if self._total_form_count > self.max_num and self.max_num > 0: 
     60                self._total_form_count = self.max_num 
    6461            initial = {TOTAL_FORM_COUNT: self._total_form_count, 
    65                        INITIAL_FORM_COUNT: self._initial_form_count, 
    66                        MAX_FORM_COUNT: self._max_form_count} 
     62                       INITIAL_FORM_COUNT: self._initial_form_count} 
    6763            self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) 
    6864         
     
    281277    attrs = {'form': form, 'extra': extra, 
    282278             'can_order': can_order, 'can_delete': can_delete, 
    283              '_max_form_count': max_num} 
     279             'max_num': max_num} 
    284280    return type(form.__name__ + 'FormSet', (formset,), attrs) 
    285281 
  • django/trunk/django/forms/models.py

    r8046 r8058  
    306306        self.queryset = queryset 
    307307        defaults = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix': prefix} 
    308         if self._max_form_count > 0: 
    309             qs = self.get_queryset()[:self._max_form_count
     308        if self.max_num > 0: 
     309            qs = self.get_queryset()[:self.max_num
    310310        else: 
    311311            qs = self.get_queryset() 
  • django/trunk/tests/modeltests/model_formsets/models.py

    r7971 r8058  
    4242...     'form-TOTAL_FORMS': '3', # the number of forms rendered 
    4343...     'form-INITIAL_FORMS': '0', # the number of forms with initial data 
    44 ...     'form-MAX_FORMS': '0', # the max number of forms 
    4544...     'form-0-name': 'Charles Baudelaire', 
    4645...     'form-1-name': 'Arthur Rimbaud', 
     
    8079...     'form-TOTAL_FORMS': '3', # the number of forms rendered 
    8180...     'form-INITIAL_FORMS': '2', # the number of forms with initial data 
    82 ...     'form-MAX_FORMS': '0', # the max number of forms 
    8381...     'form-0-id': '2', 
    8482...     'form-0-name': 'Arthur Rimbaud', 
     
    124122...     'form-TOTAL_FORMS': '4', # the number of forms rendered 
    125123...     'form-INITIAL_FORMS': '3', # the number of forms with initial data 
    126 ...     'form-MAX_FORMS': '0', # the max number of forms 
    127124...     'form-0-id': '2', 
    128125...     'form-0-name': 'Arthur Rimbaud', 
     
    154151...     'form-TOTAL_FORMS': '4', # the number of forms rendered 
    155152...     'form-INITIAL_FORMS': '3', # the number of forms with initial data 
    156 ...     'form-MAX_FORMS': '0', # the max number of forms 
    157153...     'form-0-id': '2', 
    158154...     'form-0-name': 'Walt Whitman', 
     
    185181...     'form-TOTAL_FORMS': '2', # the number of forms rendered 
    186182...     'form-INITIAL_FORMS': '1', # the number of forms with initial data 
    187 ...     'form-MAX_FORMS': '0', # the max number of forms 
    188183...     'form-0-id': '1', 
    189184...     'form-0-name': '2nd Tuesday of the Week Meeting', 
     
    243238...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    244239...     'book_set-INITIAL_FORMS': '0', # the number of forms with initial data 
    245 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    246240...     'book_set-0-title': 'Les Fleurs du Mal', 
    247241...     'book_set-1-title': '', 
     
    278272...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    279273...     'book_set-INITIAL_FORMS': '1', # the number of forms with initial data 
    280 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    281274...     'book_set-0-id': '1', 
    282275...     'book_set-0-title': 'Les Fleurs du Mal', 
     
    305298...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    306299...     'book_set-INITIAL_FORMS': '2', # the number of forms with initial data 
    307 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    308300...     'book_set-0-id': '1', 
    309301...     'book_set-0-title': 'Les Fleurs du Mal', 
  • django/trunk/tests/regressiontests/forms/formsets.py

    r7971 r8058  
    2121>>> formset = ChoiceFormSet(auto_id=False, prefix='choices') 
    2222>>> print formset 
    23 <input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_FORMS" value="0" /> 
     23<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /> 
    2424<tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> 
    2525<tr><th>Votes:</th><td><input type="text" name="choices-0-votes" /></td></tr> 
     
    3535...     'choices-TOTAL_FORMS': '1', # the number of forms rendered 
    3636...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data 
    37 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    3837...     'choices-0-choice': 'Calexico', 
    3938...     'choices-0-votes': '100', 
     
    6261...     'choices-TOTAL_FORMS': '1', # the number of forms rendered 
    6362...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data 
    64 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    6563...     'choices-0-choice': 'Calexico', 
    6664...     'choices-0-votes': '', 
     
    9391...     'choices-TOTAL_FORMS': '2', # the number of forms rendered 
    9492...     'choices-INITIAL_FORMS': '1', # the number of forms with initial data 
    95 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    9693...     'choices-0-choice': 'Calexico', 
    9794...     'choices-0-votes': '100', 
     
    115112...     'choices-TOTAL_FORMS': '2', # the number of forms rendered 
    116113...     'choices-INITIAL_FORMS': '1', # the number of forms with initial data 
    117 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    118114...     'choices-0-choice': 'Calexico', 
    119115...     'choices-0-votes': '100', 
     
    135131...     'choices-TOTAL_FORMS': '2', # the number of forms rendered 
    136132...     'choices-INITIAL_FORMS': '1', # the number of forms with initial data 
    137 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    138133...     'choices-0-choice': '', # deleted value 
    139134...     'choices-0-votes': '', # deleted value 
     
    173168...     'choices-TOTAL_FORMS': '3', # the number of forms rendered 
    174169...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data 
    175 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    176170...     'choices-0-choice': '', 
    177171...     'choices-0-votes': '', 
     
    194188...     'choices-TOTAL_FORMS': '3', # the number of forms rendered 
    195189...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data 
    196 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    197190...     'choices-0-choice': 'Calexico', 
    198191...     'choices-0-votes': '100', 
     
    215208...     'choices-TOTAL_FORMS': '3', # the number of forms rendered 
    216209...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data 
    217 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    218210...     'choices-0-choice': 'Calexico', 
    219211...     'choices-0-votes': '100', 
     
    276268...     'choices-TOTAL_FORMS': '3', # the number of forms rendered 
    277269...     'choices-INITIAL_FORMS': '2', # the number of forms with initial data 
    278 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    279270...     'choices-0-choice': 'Calexico', 
    280271...     'choices-0-votes': '100', 
     
    326317...     'choices-TOTAL_FORMS': '3', # the number of forms rendered 
    327318...     'choices-INITIAL_FORMS': '2', # the number of forms with initial data 
    328 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    329319...     'choices-0-choice': 'Calexico', 
    330320...     'choices-0-votes': '100', 
     
    353343...     'choices-TOTAL_FORMS': '4', # the number of forms rendered 
    354344...     'choices-INITIAL_FORMS': '3', # the number of forms with initial data 
    355 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    356345...     'choices-0-choice': 'Calexico', 
    357346...     'choices-0-votes': '100', 
     
    415404...     'choices-TOTAL_FORMS': '4', # the number of forms rendered 
    416405...     'choices-INITIAL_FORMS': '3', # the number of forms with initial data 
    417 ...     'choices-MAX_FORMS': '0', # the max number of forms 
    418406...     'choices-0-choice': 'Calexico', 
    419407...     'choices-0-votes': '100', 
     
    474462...     'drinks-TOTAL_FORMS': '2', # the number of forms rendered 
    475463...     'drinks-INITIAL_FORMS': '0', # the number of forms with initial data 
    476 ...     'drinks-MAX_FORMS': '0', # the max number of forms 
    477464...     'drinks-0-name': 'Gin and Tonic', 
    478465...     'drinks-1-name': 'Gin and Tonic', 
     
    496483...     'drinks-TOTAL_FORMS': '2', # the number of forms rendered 
    497484...     'drinks-INITIAL_FORMS': '0', # the number of forms with initial data 
    498 ...     'drinks-MAX_FORMS': '0', # the max number of forms 
    499485...     'drinks-0-name': 'Gin and Tonic', 
    500486...     'drinks-1-name': 'Bloody Mary',