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

Fixed #3810 -- In newforms, copy attribute dictionaries before modifying them

in place.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4894 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst 4e31a17e
...@@ -24,7 +24,10 @@ class Widget(object): ...@@ -24,7 +24,10 @@ class Widget(object):
is_hidden = False # Determines whether this corresponds to an <input type="hidden">. is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
def __init__(self, attrs=None): def __init__(self, attrs=None):
self.attrs = attrs or {} if attrs is not None:
self.attrs = attrs.copy()
else:
self.attrs = {}
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
""" """
......
# -*- coding: utf-8 -*-
# Tests to prevent against recurrences of earlier bugs.
regression_tests = r"""
It should be possible to re-use attribute dictionaries (#3810)
>>> from django.newforms import *
>>> extra_attrs = {'class': 'special'}
>>> class TestForm(Form):
... f1 = CharField(max_length=10, widget=TextInput(attrs=extra_attrs))
... f2 = CharField(widget=TextInput(attrs=extra_attrs))
>>> TestForm(auto_id=False).as_p()
u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>'
"""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from localflavor import localflavor_tests from localflavor import localflavor_tests
from regressions import regression_tests
form_tests = r""" form_tests = r"""
>>> from django.newforms import * >>> from django.newforms import *
...@@ -3297,6 +3298,7 @@ u'foo' ...@@ -3297,6 +3298,7 @@ u'foo'
__test__ = { __test__ = {
'form_tests': form_tests, 'form_tests': form_tests,
'localflavor': localflavor_tests, 'localflavor': localflavor_tests,
'regressions': regression_tests,
} }
if __name__ == "__main__": if __name__ == "__main__":
......
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