Ticket #5923: required-forms-count.diff
File required-forms-count.diff, 8.1 KB (added by , 17 years ago) |
---|
-
django/newforms/formsets.py
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 … … 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 … … 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_extra41 self.change_form_count = self. total_forms - self.num_extra42 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') … … 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``.""" -
tests/modeltests/model_formsets/models.py
30 30 31 31 >>> data = { 32 32 ... 'form-COUNT': '3', 33 ... 'form-REQUIRED': '0', # number of forms filled before 33 34 ... 'form-0-name': 'Charles Baudelaire', 34 35 ... 'form-1-name': 'Arthur Rimbaud', 35 36 ... 'form-2-name': '', … … 66 67 67 68 >>> data = { 68 69 ... 'form-COUNT': '3', 70 ... 'form-REQUIRED': '2', # number of forms filled before 69 71 ... 'form-0-id': '2', 70 72 ... 'form-0-name': 'Arthur Rimbaud', 71 73 ... 'form-1-id': '1', … … 107 109 108 110 >>> data = { 109 111 ... 'form-COUNT': '4', 112 ... 'form-REQUIRED': '3', # number of forms filled before 110 113 ... 'form-0-id': '2', 111 114 ... 'form-0-name': 'Arthur Rimbaud', 112 115 ... 'form-1-id': '1', … … 148 151 149 152 >>> data = { 150 153 ... 'book_set-COUNT': '3', 154 ... 'book_set-REQUIRED': '0', # number of forms filled before 151 155 ... 'book_set-0-title': 'Les Fleurs du Mal', 152 156 ... 'book_set-1-title': '', 153 157 ... 'book_set-2-title': '', … … 181 185 182 186 >>> data = { 183 187 ... 'book_set-COUNT': '3', 188 ... 'book_set-REQUIRED': '1', # number of forms filled before 184 189 ... 'book_set-0-id': '1', 185 190 ... 'book_set-0-title': 'Les Fleurs du Mal', 186 191 ... 'book_set-1-title': 'Le Spleen de Paris', -
tests/regressiontests/forms/formsets.py
33 33 34 34 >>> data = { 35 35 ... 'choices-COUNT': '1', # the number of forms rendered 36 ... 'choices-REQUIRED': '0', # number of forms filled before 36 37 ... 'choices-0-choice': 'Calexico', 37 38 ... 'choices-0-votes': '100', 38 39 ... } … … 58 59 59 60 >>> data = { 60 61 ... '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 61 64 ... 'choices-0-choice': 'Calexico', 62 65 ... 'choices-0-votes': '', 63 66 ... } … … 94 97 95 98 >>> data = { 96 99 ... 'choices-COUNT': '2', # the number of forms rendered 100 ... 'choices-REQUIRED': '1', # number of forms filled before 97 101 ... 'choices-0-choice': 'Calexico', 98 102 ... 'choices-0-votes': '100', 99 103 ... 'choices-1-choice': '', … … 114 118 115 119 >>> data = { 116 120 ... 'choices-COUNT': '2', # the number of forms rendered 121 ... 'choices-REQUIRED': '1', # number of forms filled before 117 122 ... 'choices-0-choice': 'Calexico', 118 123 ... 'choices-0-votes': '100', 119 124 ... 'choices-1-choice': 'The Decemberists', … … 133 138 134 139 >>> data = { 135 140 ... 'choices-COUNT': '2', # the number of forms rendered 141 ... 'choices-REQUIRED': '1', # number of forms filled before 136 142 ... 'choices-0-choice': '', # deleted value 137 143 ... 'choices-0-votes': '', # deleted value 138 144 ... 'choices-1-choice': '', … … 169 175 170 176 >>> data = { 171 177 ... 'choices-COUNT': '3', # the number of forms rendered 178 ... 'choices-REQUIRED': '0', # number of forms filled before 172 179 ... 'choices-0-choice': '', 173 180 ... 'choices-0-votes': '', 174 181 ... 'choices-1-choice': '', … … 188 195 189 196 >>> data = { 190 197 ... 'choices-COUNT': '3', # the number of forms rendered 198 ... 'choices-REQUIRED': '0', # number of forms filled before 191 199 ... 'choices-0-choice': 'Calexico', 192 200 ... 'choices-0-votes': '100', 193 201 ... 'choices-1-choice': '', … … 207 215 208 216 >>> data = { 209 217 ... 'choices-COUNT': '3', # the number of forms rendered 218 ... 'choices-REQUIRED': '0', # number of forms filled before 210 219 ... 'choices-0-choice': 'Calexico', 211 220 ... 'choices-0-votes': '100', 212 221 ... 'choices-1-choice': 'The Decemberists', … … 244 253 245 254 >>> data = { 246 255 ... 'choices-COUNT': '3', # the number of forms rendered 256 ... 'choices-REQUIRED': '1', # number of forms filled before 247 257 ... 'choices-0-choice': 'Calexico', 248 258 ... 'choices-0-votes': '100', 249 259 ... 'choices-1-choice': '', … … 289 299 290 300 >>> data = { 291 301 ... 'choices-COUNT': '3', # the number of forms rendered 302 ... 'choices-REQUIRED': '2', # number of forms filled before 292 303 ... 'choices-0-choice': 'Calexico', 293 304 ... 'choices-0-votes': '100', 294 305 ... 'choices-0-DELETE': '', … … 336 347 337 348 >>> data = { 338 349 ... 'choices-COUNT': '3', # the number of forms rendered 350 ... 'choices-REQUIRED': '2', # number of forms filled before 339 351 ... 'choices-0-choice': 'Calexico', 340 352 ... 'choices-0-votes': '100', 341 353 ... 'choices-0-ORDER': '1', … … 391 403 392 404 >>> data = { 393 405 ... 'choices-COUNT': '4', # the number of forms rendered 406 ... 'choices-REQUIRED': '3', # number of forms filled before 394 407 ... 'choices-0-choice': 'Calexico', 395 408 ... 'choices-0-votes': '100', 396 409 ... 'choices-0-ORDER': '1', … … 451 464 452 465 >>> data = { 453 466 ... 'drinks-COUNT': '2', 467 ... 'drinks-REQUIRED': '0', # number of forms filled before 454 468 ... 'drinks-0-name': 'Gin and Tonic', 455 469 ... 'drinks-1-name': 'Gin and Tonic', 456 470 ... } … … 471 485 472 486 >>> data = { 473 487 ... 'drinks-COUNT': '2', 488 ... 'drinks-REQUIRED': '0', # number of forms filled before 474 489 ... 'drinks-0-name': 'Gin and Tonic', 475 490 ... 'drinks-1-name': 'Bloody Mary', 476 491 ... }