Author: russellm
Date: 2009-04-28 09:22:39 -0500 (Tue, 28 Apr 2009)
New Revision: 10644

Modified:
   django/branches/releases/1.0.X/django/forms/formsets.py
   django/branches/releases/1.0.X/tests/regressiontests/forms/formsets.py
Log:
[1.0.X] 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.

Merge of r10643 from trunk.

Modified: django/branches/releases/1.0.X/django/forms/formsets.py
===================================================================
--- django/branches/releases/1.0.X/django/forms/formsets.py     2009-04-28 
14:17:18 UTC (rev 10643)
+++ django/branches/releases/1.0.X/django/forms/formsets.py     2009-04-28 
14:22:39 UTC (rev 10644)
@@ -158,18 +158,18 @@
                 # 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.

Modified: django/branches/releases/1.0.X/tests/regressiontests/forms/formsets.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/forms/formsets.py      
2009-04-28 14:17:18 UTC (rev 10643)
+++ django/branches/releases/1.0.X/tests/regressiontests/forms/formsets.py      
2009-04-28 14:22:39 UTC (rev 10644)
@@ -394,7 +394,19 @@
 {'votes': 500, 'ORDER': None, 'choice': u'The Decemberists'}
 {'votes': 50, 'ORDER': None, 'choice': u'Basia Bulat'}
 
+Ordering should work with blank fieldsets.
 
+>>> data = {
+...     'choices-TOTAL_FORMS': '3', # the number of forms rendered
+...     'choices-INITIAL_FORMS': '0', # the number of forms with initial data
+... }
+
+>>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
+>>> formset.is_valid()
+True
+>>> for form in formset.ordered_forms:
+...    print form.cleaned_data
+
 # FormSets with ordering + deletion ###########################################
 
 Let's try throwing ordering and deletion into the same form.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to