diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-28 14:17:18 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-28 14:17:18 +0000 |
| commit | 2ba9df2f41cd649b42f5d7452aa2393aa6131f32 (patch) | |
| tree | 86877b1705242e37916bc9fd3fbba1f794a3fb7f /django/forms/formsets.py | |
| parent | 0c1d38bdf4884121e322c557e09721af85c10eb3 (diff) | |
Fixed #10082 -- Modified BaseFormSet so that ordering checks work when the formset is empty. Thanks to Petr Marhoun for the report and test case, and bmathieu for the fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/formsets.py')
| -rw-r--r-- | django/forms/formsets.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 66ccd6d08d..bb8e3107e1 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -170,18 +170,18 @@ class BaseFormSet(StrAndUnicode): # don't add data marked for deletion to self.ordered_data if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: continue - # A sort function to order things numerically ascending, but - # None should be sorted below anything else. Allowing None as - # a comparison value makes it so we can leave ordering fields - # blamk. - def compare_ordering_values(x, y): - if x[1] is None: - return 1 - if y[1] is None: - return -1 - return x[1] - y[1] self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME])) # After we're done populating self._ordering, sort it. + # A sort function to order things numerically ascending, but + # None should be sorted below anything else. Allowing None as + # a comparison value makes it so we can leave ordering fields + # blamk. + def compare_ordering_values(x, y): + if x[1] is None: + return 1 + if y[1] is None: + return -1 + return x[1] - y[1] self._ordering.sort(compare_ordering_values) # Return a list of form.cleaned_data dicts in the order spcified by # the form data. |
