Ticket #3489: sprint-patch1.diff

File sprint-patch1.diff, 2.5 KB (added by Jonathan Buchanan, 17 years ago)

Previous patch no longer works due to a deepcopy error

  • django/newforms/fields.py

     
    22Field classes
    33"""
    44
     5import copy
    56import datetime
    67import re
    78import time
     
    100101        """
    101102        return {}
    102103
     104    def __deepcopy__(self, memo):
     105        result = copy.copy(self)
     106        memo[id(self)] = result
     107        result.widget = copy.deepcopy(self.widget, memo)
     108        return result
     109
    103110class CharField(Field):
    104111    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    105112        self.max_length, self.min_length = max_length, min_length
  • django/newforms/forms.py

     
    3131        dict.__init__(self, dict(data))
    3232
    3333    def copy(self):
    34         return SortedDictFromList([(k, copy.copy(v)) for k, v in self.items()])
     34        return SortedDictFromList([(k, copy.deepcopy(v)) for k, v in self.items()])
    3535
    3636class DeclarativeFieldsMetaclass(type):
    3737    """
  • tests/regressiontests/forms/tests.py

     
    26812681...         super(Person, self).__init__(*args, **kwargs)
    26822682...         if names_required:
    26832683...             self.fields['first_name'].required = True
     2684...             self.fields['first_name'].widget.attrs['class'] = 'required'
    26842685...             self.fields['last_name'].required = True
     2686...             self.fields['last_name'].widget.attrs['class'] = 'required'
    26852687>>> f = Person(names_required=False)
    26862688>>> f['first_name'].field.required, f['last_name'].field.required
    26872689(False, False)
     2690>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2691({}, {})
    26882692>>> f = Person(names_required=True)
    26892693>>> f['first_name'].field.required, f['last_name'].field.required
    26902694(True, True)
     2695>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2696({'class': 'required'}, {'class': 'required'})
    26912697>>> f = Person(names_required=False)
    26922698>>> f['first_name'].field.required, f['last_name'].field.required
    26932699(False, False)
     2700>>> f['first_name'].field.widget.attrs, f['last_name'].field.widget.attrs
     2701({}, {})
    26942702>>> class Person(Form):
    26952703...     first_name = CharField(max_length=30)
    26962704...     last_name = CharField(max_length=30)
Back to Top