Ticket #20850: 0001-Fix-MultiWidgets-not-respecting-subwidgets-need_mult.patch

File 0001-Fix-MultiWidgets-not-respecting-subwidgets-need_mult.patch, 2.1 KB (added by Tim Heap, 11 years ago)
  • django/forms/widgets.py

    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):  
    840840        obj.widgets = copy.deepcopy(self.widgets)
    841841        return obj
    842842
     843    @property
     844    def needs_multipart_form(self):
     845        return any(w.needs_multipart_form for w in self.widgets)
     846
     847
    843848class SplitDateTimeWidget(MultiWidget):
    844849    """
    845850    A Widget that splits datetime input into two <input type="text"> boxes.
  • tests/forms_tests/tests/test_widgets.py

    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""")  
    849849        w = MyMultiWidget(widgets=(TextInput(attrs={'class': 'big'}), TextInput(attrs={'class': 'small'})), attrs={'id': 'bar'})
    850850        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" />')
    851851
     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
    852860    def test_splitdatetime(self):
    853861        w = SplitDateTimeWidget()
    854862        self.assertHTMLEqual(w.render('date', ''), '<input type="text" name="date_0" /><input type="text" name="date_1" />')
Back to Top