Skip to content

Commit

Permalink
Added a __deepcopy__() method to the Widget class in order to avoid a…
Browse files Browse the repository at this point in the history
… 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
malcolmt committed Oct 4, 2007
1 parent 4d8b51f commit b1cc331
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions django/newforms/widgets.py
Expand Up @@ -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
Expand All @@ -32,6 +34,12 @@ def __init__(self, attrs=None):
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.
Expand Down

0 comments on commit b1cc331

Please sign in to comment.