Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms-admin: Fixed #6926. Formset management forms now use the pro…

…per prefix. Thanks, msundstr.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 613c391461cec08786c6ecfdfb287c740d47b1e4 1 parent b2b6fb6
Joseph Kocherhans authored March 30, 2008
1  AUTHORS
@@ -263,6 +263,7 @@ answer newbie questions, and generally made Django that much better:
263 263
     Eric Moritz <http://eric.themoritzfamily.com/>
264 264
     mrmachine <real.human@mrmachine.net>
265 265
     Robin Munn <http://www.geekforgod.com/>
  266
+    msundstr
266 267
     Robert Myers <myer0052@gmail.com>
267 268
     Nebojša Dorđević
268 269
     Doug Napoleone <doug@dougma.com>
17  django/newforms/formsets.py
@@ -40,20 +40,21 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
40 40
         self._non_form_errors = None
41 41
         # initialization is different depending on whether we recieved data, initial, or nothing
42 42
         if data or files:
43  
-            self.management_form = ManagementForm(data, files, auto_id=self.auto_id, prefix=self.prefix)
  43
+            self.management_form = ManagementForm(data, auto_id=self.auto_id, prefix=self.prefix)
44 44
             if self.management_form.is_valid():
45 45
                 self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT]
46 46
                 self._initial_form_count = self.management_form.cleaned_data[INITIAL_FORM_COUNT]
47 47
             else:
48 48
                 raise ValidationError('ManagementForm data is missing or has been tampered with')
49  
-        elif initial:
50  
-            self._initial_form_count = len(initial)
51  
-            self._total_form_count = self._initial_form_count + self.extra
52 49
         else:
53  
-            self._initial_form_count = 0
54  
-            self._total_form_count = self.extra
55  
-        initial = {TOTAL_FORM_COUNT: self._total_form_count, INITIAL_FORM_COUNT: self._initial_form_count}
56  
-        self.management_form = ManagementForm(initial=initial, auto_id=auto_id, prefix=prefix)
  50
+            if initial:
  51
+                self._initial_form_count = len(initial)
  52
+                self._total_form_count = self._initial_form_count + self.extra
  53
+            else:
  54
+                self._initial_form_count = 0
  55
+                self._total_form_count = self.extra
  56
+            initial = {TOTAL_FORM_COUNT: self._total_form_count, INITIAL_FORM_COUNT: self._initial_form_count}
  57
+            self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix)
57 58
 
58 59
         # instantiate all the forms and put them in self.forms
59 60
         self.forms = []
17  tests/regressiontests/forms/formsets.py
@@ -494,4 +494,21 @@
494 494
 >>> for error in formset.non_form_errors():
495 495
 ...     print error
496 496
 
  497
+
  498
+# Regression test for #6926 ##################################################
  499
+
  500
+Make sure the management form has the correct prefix.
  501
+
  502
+>>> formset = FavoriteDrinksFormSet()
  503
+>>> formset.management_form.prefix
  504
+'form'
  505
+
  506
+>>> formset = FavoriteDrinksFormSet(data={})
  507
+>>> formset.management_form.prefix
  508
+'form'
  509
+
  510
+>>> formset = FavoriteDrinksFormSet(initial={})
  511
+>>> formset.management_form.prefix
  512
+'form'
  513
+
497 514
 """

0 notes on commit 613c391

Please sign in to comment.
Something went wrong with that request. Please try again.