Ticket #10082: blank-ordered-fieldsets.diff

File blank-ordered-fieldsets.diff, 1.5 KB (added by Petr Marhoun <petr.marhoun@…>, 16 years ago)
  • django/forms/formsets.py

    === modified file 'django/forms/formsets.py'
     
    170170                    return x[1] - y[1]
    171171                self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME]))
    172172            # After we're done populating self._ordering, sort it.
    173             self._ordering.sort(compare_ordering_values)
     173            if self._ordering:
     174                self._ordering.sort(compare_ordering_values)
    174175        # Return a list of form.cleaned_data dicts in the order spcified by
    175176        # the form data.
    176177        return [self.forms[i[0]] for i in self._ordering]
  • tests/regressiontests/forms/formsets.py

    === modified file 'tests/regressiontests/forms/formsets.py'
     
    366366{'votes': 500, 'ORDER': None, 'choice': u'The Decemberists'}
    367367{'votes': 50, 'ORDER': None, 'choice': u'Basia Bulat'}
    368368
     369Ordering should work with blank fieldsets.
     370
     371>>> data = {
     372...     'choices-TOTAL_FORMS': '3', # the number of forms rendered
     373...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data
     374... }
     375
     376>>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
     377>>> formset.is_valid()
     378True
     379>>> for form in formset.ordered_forms:
     380...    print form.cleaned_data
    369381
    370382# FormSets with ordering + deletion ###########################################
    371383
Back to Top