Kaydet (Commit) b1cc3318 authored tarafından Malcolm Tredinnick's avatar Malcolm Tredinnick

Added a __deepcopy__() method to the Widget class in order to avoid a number of…

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
üst 4d8b51f6
...@@ -7,7 +7,9 @@ try: ...@@ -7,7 +7,9 @@ try:
except NameError: except NameError:
from sets import Set as set # Python 2.3 fallback from sets import Set as set # Python 2.3 fallback
import copy
from itertools import chain from itertools import chain
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.html import escape from django.utils.html import escape
from django.utils.translation import ugettext from django.utils.translation import ugettext
...@@ -32,6 +34,12 @@ class Widget(object): ...@@ -32,6 +34,12 @@ class Widget(object):
else: else:
self.attrs = {} 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): def render(self, name, value, attrs=None):
""" """
Returns this Widget rendered as HTML, as a Unicode string. Returns this Widget rendered as HTML, as a Unicode string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment