Changeset 8058
- Timestamp:
- 07/22/08 23:28:52 (5 months ago)
- Files:
-
- django/trunk/django/forms/formsets.py (modified) (5 diffs)
- django/trunk/django/forms/models.py (modified) (1 diff)
- django/trunk/tests/modeltests/model_formsets/models.py (modified) (8 diffs)
- django/trunk/tests/regressiontests/forms/formsets.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/forms/formsets.py
r8046 r8058 11 11 TOTAL_FORM_COUNT = 'TOTAL_FORMS' 12 12 INITIAL_FORM_COUNT = 'INITIAL_FORMS' 13 MAX_FORM_COUNT = 'MAX_FORMS'14 13 ORDERING_FIELD_NAME = 'ORDER' 15 14 DELETION_FIELD_NAME = 'DELETE' … … 24 23 self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 25 24 self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 26 self.base_fields[MAX_FORM_COUNT] = IntegerField(widget=HiddenInput)27 25 super(ManagementForm, self).__init__(*args, **kwargs) 28 26 … … 48 46 self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT] 49 47 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]51 48 else: 52 49 raise ValidationError('ManagementForm data is missing or has been tampered with') … … 54 51 if initial: 55 52 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_count53 if self._initial_form_count > self.max_num and self.max_num > 0: 54 self._initial_form_count = self.max_num 58 55 self._total_form_count = self._initial_form_count + self.extra 59 56 else: 60 57 self._initial_form_count = 0 61 58 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_count59 if self._total_form_count > self.max_num and self.max_num > 0: 60 self._total_form_count = self.max_num 64 61 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} 67 63 self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) 68 64 … … 281 277 attrs = {'form': form, 'extra': extra, 282 278 'can_order': can_order, 'can_delete': can_delete, 283 ' _max_form_count': max_num}279 'max_num': max_num} 284 280 return type(form.__name__ + 'FormSet', (formset,), attrs) 285 281 django/trunk/django/forms/models.py
r8046 r8058 306 306 self.queryset = queryset 307 307 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] 310 310 else: 311 311 qs = self.get_queryset() django/trunk/tests/modeltests/model_formsets/models.py
r7971 r8058 42 42 ... 'form-TOTAL_FORMS': '3', # the number of forms rendered 43 43 ... 'form-INITIAL_FORMS': '0', # the number of forms with initial data 44 ... 'form-MAX_FORMS': '0', # the max number of forms45 44 ... 'form-0-name': 'Charles Baudelaire', 46 45 ... 'form-1-name': 'Arthur Rimbaud', … … 80 79 ... 'form-TOTAL_FORMS': '3', # the number of forms rendered 81 80 ... 'form-INITIAL_FORMS': '2', # the number of forms with initial data 82 ... 'form-MAX_FORMS': '0', # the max number of forms83 81 ... 'form-0-id': '2', 84 82 ... 'form-0-name': 'Arthur Rimbaud', … … 124 122 ... 'form-TOTAL_FORMS': '4', # the number of forms rendered 125 123 ... 'form-INITIAL_FORMS': '3', # the number of forms with initial data 126 ... 'form-MAX_FORMS': '0', # the max number of forms127 124 ... 'form-0-id': '2', 128 125 ... 'form-0-name': 'Arthur Rimbaud', … … 154 151 ... 'form-TOTAL_FORMS': '4', # the number of forms rendered 155 152 ... 'form-INITIAL_FORMS': '3', # the number of forms with initial data 156 ... 'form-MAX_FORMS': '0', # the max number of forms157 153 ... 'form-0-id': '2', 158 154 ... 'form-0-name': 'Walt Whitman', … … 185 181 ... 'form-TOTAL_FORMS': '2', # the number of forms rendered 186 182 ... 'form-INITIAL_FORMS': '1', # the number of forms with initial data 187 ... 'form-MAX_FORMS': '0', # the max number of forms188 183 ... 'form-0-id': '1', 189 184 ... 'form-0-name': '2nd Tuesday of the Week Meeting', … … 243 238 ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered 244 239 ... 'book_set-INITIAL_FORMS': '0', # the number of forms with initial data 245 ... 'book_set-MAX_FORMS': '0', # the max number of forms246 240 ... 'book_set-0-title': 'Les Fleurs du Mal', 247 241 ... 'book_set-1-title': '', … … 278 272 ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered 279 273 ... 'book_set-INITIAL_FORMS': '1', # the number of forms with initial data 280 ... 'book_set-MAX_FORMS': '0', # the max number of forms281 274 ... 'book_set-0-id': '1', 282 275 ... 'book_set-0-title': 'Les Fleurs du Mal', … … 305 298 ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered 306 299 ... 'book_set-INITIAL_FORMS': '2', # the number of forms with initial data 307 ... 'book_set-MAX_FORMS': '0', # the max number of forms308 300 ... 'book_set-0-id': '1', 309 301 ... 'book_set-0-title': 'Les Fleurs du Mal', django/trunk/tests/regressiontests/forms/formsets.py
r7971 r8058 21 21 >>> formset = ChoiceFormSet(auto_id=False, prefix='choices') 22 22 >>> 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" /> 24 24 <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> 25 25 <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" /></td></tr> … … 35 35 ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered 36 36 ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 37 ... 'choices-MAX_FORMS': '0', # the max number of forms38 37 ... 'choices-0-choice': 'Calexico', 39 38 ... 'choices-0-votes': '100', … … 62 61 ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered 63 62 ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 64 ... 'choices-MAX_FORMS': '0', # the max number of forms65 63 ... 'choices-0-choice': 'Calexico', 66 64 ... 'choices-0-votes': '', … … 93 91 ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered 94 92 ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data 95 ... 'choices-MAX_FORMS': '0', # the max number of forms96 93 ... 'choices-0-choice': 'Calexico', 97 94 ... 'choices-0-votes': '100', … … 115 112 ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered 116 113 ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data 117 ... 'choices-MAX_FORMS': '0', # the max number of forms118 114 ... 'choices-0-choice': 'Calexico', 119 115 ... 'choices-0-votes': '100', … … 135 131 ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered 136 132 ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data 137 ... 'choices-MAX_FORMS': '0', # the max number of forms138 133 ... 'choices-0-choice': '', # deleted value 139 134 ... 'choices-0-votes': '', # deleted value … … 173 168 ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered 174 169 ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 175 ... 'choices-MAX_FORMS': '0', # the max number of forms176 170 ... 'choices-0-choice': '', 177 171 ... 'choices-0-votes': '', … … 194 188 ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered 195 189 ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 196 ... 'choices-MAX_FORMS': '0', # the max number of forms197 190 ... 'choices-0-choice': 'Calexico', 198 191 ... 'choices-0-votes': '100', … … 215 208 ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered 216 209 ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 217 ... 'choices-MAX_FORMS': '0', # the max number of forms218 210 ... 'choices-0-choice': 'Calexico', 219 211 ... 'choices-0-votes': '100', … … 276 268 ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered 277 269 ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data 278 ... 'choices-MAX_FORMS': '0', # the max number of forms279 270 ... 'choices-0-choice': 'Calexico', 280 271 ... 'choices-0-votes': '100', … … 326 317 ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered 327 318 ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data 328 ... 'choices-MAX_FORMS': '0', # the max number of forms329 319 ... 'choices-0-choice': 'Calexico', 330 320 ... 'choices-0-votes': '100', … … 353 343 ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered 354 344 ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data 355 ... 'choices-MAX_FORMS': '0', # the max number of forms356 345 ... 'choices-0-choice': 'Calexico', 357 346 ... 'choices-0-votes': '100', … … 415 404 ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered 416 405 ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data 417 ... 'choices-MAX_FORMS': '0', # the max number of forms418 406 ... 'choices-0-choice': 'Calexico', 419 407 ... 'choices-0-votes': '100', … … 474 462 ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered 475 463 ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data 476 ... 'drinks-MAX_FORMS': '0', # the max number of forms477 464 ... 'drinks-0-name': 'Gin and Tonic', 478 465 ... 'drinks-1-name': 'Gin and Tonic', … … 496 483 ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered 497 484 ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data 498 ... 'drinks-MAX_FORMS': '0', # the max number of forms499 485 ... 'drinks-0-name': 'Gin and Tonic', 500 486 ... 'drinks-1-name': 'Bloody Mary',
