Ticket #10082: compare_ordering_values.patch
File compare_ordering_values.patch, 1.6 KB (added by , 16 years ago) |
---|
-
django/forms/formsets.py
old new 158 158 # don't add data marked for deletion to self.ordered_data 159 159 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 160 160 continue 161 # A sort function to order things numerically ascending, but162 # None should be sorted below anything else. Allowing None as163 # a comparison value makes it so we can leave ordering fields164 # blamk.165 def compare_ordering_values(x, y):166 if x[1] is None:167 return 1168 if y[1] is None:169 return -1170 return x[1] - y[1]171 161 self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME])) 172 162 # After we're done populating self._ordering, sort it. 163 164 # A sort function to order things numerically ascending, but 165 # None should be sorted below anything else. Allowing None as 166 # a comparison value makes it so we can leave ordering fields 167 # blamk. 168 def compare_ordering_values(x, y): 169 if x[1] is None: 170 return 1 171 if y[1] is None: 172 return -1 173 return x[1] - y[1] 173 174 self._ordering.sort(compare_ordering_values) 174 175 # Return a list of form.cleaned_data dicts in the order spcified by 175 176 # the form data.