Ticket #25085: 25085.diff

File 25085.diff, 1.6 KB (added by ericfc, 9 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 896984d..c744d09 100644
    a b class Select(Widget):  
    521521        # more than once.
    522522        self.choices = list(choices)
    523523
     524    def __deepcopy__(self, memo):
     525        obj = copy.copy(self)
     526        obj.attrs = self.attrs.copy()
     527        obj.choices = copy.copy(self.choices)
     528        memo[id(self)] = obj
     529        return obj
     530
    524531    def render(self, name, value, attrs=None, choices=()):
    525532        if value is None:
    526533            value = ''
  • 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 40ff750..8b2d0c0 100644
    a b class SelectDateWidgetTests(SimpleTestCase):  
    19971997        # label tag is correctly associated with first rendered dropdown
    19981998        a = GetDate({'mydate_month': '1', 'mydate_day': '1', 'mydate_year': '2010'})
    19991999        self.assertIn('<label for="id_mydate_day">', a.as_p())
     2000
     2001
     2002class SelectWidgetTests(SimpleTestCase):
     2003
     2004    def test_deepcopy(self):
     2005        """
     2006        Ensure that __deepcopy__ copies all fields properly.
     2007        Refs #25085
     2008        """
     2009        widget = Select()
     2010        obj = copy.deepcopy(widget)
     2011        self.assertTrue(widget is not obj)
     2012        self.assertTrue(widget.choices == obj.choices)
     2013        self.assertTrue(widget.choices is not obj.choices)
     2014        self.assertTrue(widget.attrs == obj.attrs)
     2015        self.assertTrue(widget.attrs is not obj.attrs)
Back to Top