From e2ce874f003e8ca0cdc89b833182b9791ee0e020 Mon Sep 17 00:00:00 2001
From: Tim Heap <tim@ionata.com.au>
Date: Fri, 2 Aug 2013 12:43:50 +1000
Subject: [PATCH] Fix MultiWidgets not respecting subwidgets
need_multipart_form
This fixes bug #20850.
---
django/forms/widgets.py | 5 +++++
tests/forms_tests/tests/test_widgets.py | 8 ++++++++
2 files changed, 13 insertions(+)
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 784ccda..0a5059a 100644
a
|
b
|
class MultiWidget(Widget):
|
840 | 840 | obj.widgets = copy.deepcopy(self.widgets) |
841 | 841 | return obj |
842 | 842 | |
| 843 | @property |
| 844 | def needs_multipart_form(self): |
| 845 | return any(w.needs_multipart_form for w in self.widgets) |
| 846 | |
| 847 | |
843 | 848 | class SplitDateTimeWidget(MultiWidget): |
844 | 849 | """ |
845 | 850 | A Widget that splits datetime input into two <input type="text"> boxes. |
diff --git a/tests/forms_tests/tests/test_widgets.py b/tests/forms_tests/tests/test_widgets.py
index 4c566dc..06ee2d6 100644
a
|
b
|
beatle J R Ringo False""")
|
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" />') |