Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Backport of 75c87e2 from master
  • Loading branch information...
commit 891cdf120a0751b71eb534e14f814f574904ec44 1 parent ea7bef3
@timheap timheap authored timgraham committed
View
5 django/forms/widgets.py
@@ -838,6 +838,11 @@ def __deepcopy__(self, memo):
obj.widgets = copy.deepcopy(self.widgets)
return obj
+ @property
+ def needs_multipart_form(self):
+ return any(w.needs_multipart_form for w in self.widgets)
+
+
class SplitDateTimeWidget(MultiWidget):
"""
A Widget that splits datetime input into two <input type="text"> boxes.
View
8 tests/forms_tests/tests/test_widgets.py
@@ -849,6 +849,14 @@ def format_output(self, rendered_widgets):
w = MyMultiWidget(widgets=(TextInput(attrs={'class': 'big'}), TextInput(attrs={'class': 'small'})), attrs={'id': 'bar'})
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" />')
+ # Test needs_multipart_form=True if any widget needs it
+ w = MyMultiWidget(widgets=(TextInput(), FileInput()))
+ self.assertTrue(w.needs_multipart_form)
+
+ # Test needs_multipart_form=False if no widget needs it
+ w = MyMultiWidget(widgets=(TextInput(), TextInput()))
+ self.assertFalse(w.needs_multipart_form)
+
def test_splitdatetime(self):
w = SplitDateTimeWidget()
self.assertHTMLEqual(w.render('date', ''), '<input type="text" name="date_0" /><input type="text" name="date_1" />')
Please sign in to comment.
Something went wrong with that request. Please try again.