diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index 18bba31897..58d8ab1322 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -24,7 +24,10 @@ class Widget(object): is_hidden = False # Determines whether this corresponds to an . 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): """ diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py new file mode 100644 index 0000000000..dc5232a8f0 --- /dev/null +++ b/tests/regressiontests/forms/regressions.py @@ -0,0 +1,13 @@ +# -*- 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'
F1:
\nF2:
' +""" diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 0bd87c1751..8ecc9f0205 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from localflavor import localflavor_tests +from regressions import regression_tests form_tests = r""" >>> from django.newforms import * @@ -3297,6 +3298,7 @@ u'foo' __test__ = { 'form_tests': form_tests, 'localflavor': localflavor_tests, + 'regressions': regression_tests, } if __name__ == "__main__":