summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-04 01:12:00 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-04 01:12:00 +0000
commitb1cc3318c7ac740784b556e16bae594bc20010f4 (patch)
tree3758850c5879191f60367013738bce54bab9f0c4
parent4d8b51f60c78b79186b53b9c55aa7169062603b9 (diff)
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6450 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/newforms/widgets.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index 0e7752499e..355695efd2 100644
--- a/django/newforms/widgets.py
+++ b/django/newforms/widgets.py
@@ -7,7 +7,9 @@ try:
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 @@ class Widget(object):
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.