Ticket #3489: deepcopy.diff

File deepcopy.diff, 1.8 KB (added by Jonathan Buchanan <jonathan.buchanan@…>, 18 years ago)

Copying of fields with deepcopy and regression test

  • django/newforms/forms.py

     
    2828        dict.__init__(self, dict(data))
    2929
    3030    def copy(self):
    31         return SortedDictFromList([(k, copy.copy(v)) for k, v in self.items()])
     31        return SortedDictFromList([(k, copy.deepcopy(v)) for k, v in self.items()])
    3232
    3333class DeclarativeFieldsMetaclass(type):
    3434    """
  • tests/regressiontests/forms/tests.py

     
    23972397...         super(Person, self).__init__(*args, **kwargs)
    23982398...         if names_required:
    23992399...             self.fields['first_name'].required = True
     2400...             self.fields['first_name'].widget.attrs['class'] = 'required'
    24002401...             self.fields['last_name'].required = True
     2402...             self.fields['last_name'].widget.attrs['class'] = 'required'
    24012403>>> f = Person(names_required=False)
    24022404>>> f['first_name'].field.required, f['last_name'].field.required
    24032405(False, False)
     2406>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2407({}, {})
    24042408>>> f = Person(names_required=True)
    24052409>>> f['first_name'].field.required, f['last_name'].field.required
    24062410(True, True)
     2411>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2412({'class': 'required'}, {'class': 'required'})
    24072413>>> f = Person(names_required=False)
    24082414>>> f['first_name'].field.required, f['last_name'].field.required
    24092415(False, False)
     2416>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2417({}, {})
    24102418>>> class Person(Form):
    24112419...     first_name = CharField(max_length=30)
    24122420...     last_name = CharField(max_length=30)
Back to Top