Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.6.x] Fixed #20850 -- Added MultiWidget.needs_multipart_form

Backport of 75c87e2 from master
  • Loading branch information...
commit 891cdf120a0751b71eb534e14f814f574904ec44 1 parent ea7bef3
Tim Heap authored August 05, 2013 timgraham committed August 05, 2013
5  django/forms/widgets.py
@@ -838,6 +838,11 @@ def __deepcopy__(self, memo):
838 838
         obj.widgets = copy.deepcopy(self.widgets)
839 839
         return obj
840 840
 
  841
+    @property
  842
+    def needs_multipart_form(self):
  843
+        return any(w.needs_multipart_form for w in self.widgets)
  844
+
  845
+
841 846
 class SplitDateTimeWidget(MultiWidget):
842 847
     """
843 848
     A Widget that splits datetime input into two <input type="text"> boxes.
8  tests/forms_tests/tests/test_widgets.py
@@ -849,6 +849,14 @@ def format_output(self, rendered_widgets):
849 849
         w = MyMultiWidget(widgets=(TextInput(attrs={'class': 'big'}), TextInput(attrs={'class': 'small'})), attrs={'id': 'bar'})
850 850
         self.assertHTMLEqual(w.render('name', ['john', 'lennon']), '<input id="bar_0" type="text" class="big" value="john" name="name_0" /><br /><input id="bar_1" type="text" class="small" value="lennon" name="name_1" />')
851 851
 
  852
+        # Test needs_multipart_form=True if any widget needs it
  853
+        w = MyMultiWidget(widgets=(TextInput(), FileInput()))
  854
+        self.assertTrue(w.needs_multipart_form)
  855
+
  856
+        # Test needs_multipart_form=False if no widget needs it
  857
+        w = MyMultiWidget(widgets=(TextInput(), TextInput()))
  858
+        self.assertFalse(w.needs_multipart_form)
  859
+
852 860
     def test_splitdatetime(self):
853 861
         w = SplitDateTimeWidget()
854 862
         self.assertHTMLEqual(w.render('date', ''), '<input type="text" name="date_0" /><input type="text" name="date_1" />')

0 notes on commit 891cdf1

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