Author: mtredinnick
Date: 2007-10-03 20:12:00 -0500 (Wed, 03 Oct 2007)
New Revision: 6450

Modified:
   django/trunk/django/newforms/widgets.py
Log:
Added a __deepcopy__() method to the Widget class in order to avoid a number of 
easy-to-trigger problems when copying Widget subclasses. Subclasses which are 
intended to have extra mutable fields should override this method. Refs #5505.


Modified: django/trunk/django/newforms/widgets.py
===================================================================
--- django/trunk/django/newforms/widgets.py     2007-10-03 22:21:43 UTC (rev 
6449)
+++ django/trunk/django/newforms/widgets.py     2007-10-04 01:12:00 UTC (rev 
6450)
@@ -7,7 +7,9 @@
 except NameError:
     from sets import Set as set   # Python 2.3 fallback
 
+import copy
 from itertools import chain
+
 from django.utils.datastructures import MultiValueDict
 from django.utils.html import escape
 from django.utils.translation import ugettext
@@ -32,6 +34,12 @@
         else:
             self.attrs = {}
 
+    def __deepcopy__(self, memo):
+        obj = copy.copy(self)
+        obj.attrs = self.attrs.copy()
+        memo[id(self)] = obj
+        return obj
+
     def render(self, name, value, attrs=None):
         """
         Returns this Widget rendered as HTML, as a Unicode string.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to