Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit b1cc3318c7ac740784b556e16bae594bc20010f4 1 parent 4d8b51f
Malcolm Tredinnick authored October 04, 2007

Showing 1 changed file with 8 additions and 0 deletions. Show diff stats Hide diff stats

  1. 8  django/newforms/widgets.py
8  django/newforms/widgets.py
@@ -7,7 +7,9 @@
7 7
 except NameError:
8 8
     from sets import Set as set   # Python 2.3 fallback
9 9
 
  10
+import copy
10 11
 from itertools import chain
  12
+
11 13
 from django.utils.datastructures import MultiValueDict
12 14
 from django.utils.html import escape
13 15
 from django.utils.translation import ugettext
@@ -32,6 +34,12 @@ def __init__(self, attrs=None):
32 34
         else:
33 35
             self.attrs = {}
34 36
 
  37
+    def __deepcopy__(self, memo):
  38
+        obj = copy.copy(self)
  39
+        obj.attrs = self.attrs.copy()
  40
+        memo[id(self)] = obj
  41
+        return obj
  42
+
35 43
     def render(self, name, value, attrs=None):
36 44
         """
37 45
         Returns this Widget rendered as HTML, as a Unicode string.

0 notes on commit b1cc331

Please sign in to comment.
Something went wrong with that request. Please try again.