Changeset 6668
- Timestamp:
- 11/10/07 22:44:20 (8 months ago)
- Files:
-
- django/trunk/django/newforms/forms.py (modified) (4 diffs)
- django/trunk/django/newforms/models.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/forms.py
r6352 r6668 3 3 """ 4 4 5 importcopy5 from copy import deepcopy 6 6 7 7 from django.utils.datastructures import SortedDict … … 21 21 name = name[0].upper() + name[1:] 22 22 return name.replace('_', ' ') 23 24 class SortedDictFromList(SortedDict):25 "A dictionary that keeps its keys in the order in which they're inserted."26 # This is different than django.utils.datastructures.SortedDict, because27 # this takes a list/tuple as the argument to __init__().28 def __init__(self, data=None):29 if data is None: data = []30 self.keyOrder = [d[0] for d in data]31 dict.__init__(self, dict(data))32 33 def copy(self):34 return SortedDictFromList([(k, copy.deepcopy(v)) for k, v in self.items()])35 23 36 24 class DeclarativeFieldsMetaclass(type): … … 50 38 fields = base.base_fields.items() + fields 51 39 52 attrs['base_fields'] = SortedDict FromList(fields)40 attrs['base_fields'] = SortedDict(fields) 53 41 return type.__new__(cls, name, bases, attrs) 54 42 … … 75 63 # Instances should always modify self.fields; they should not modify 76 64 # self.base_fields. 77 self.fields = self.base_fields.copy()65 self.fields = deepcopy(self.base_fields) 78 66 79 67 def __unicode__(self): django/trunk/django/newforms/models.py
r6627 r6668 6 6 from django.utils.translation import ugettext 7 7 from django.utils.encoding import smart_unicode 8 from django.utils.datastructures import SortedDict 8 9 9 10 from util import ValidationError 10 from forms import BaseForm , SortedDictFromList11 from forms import BaseForm 11 12 from fields import Field, ChoiceField 12 13 from widgets import Select, SelectMultiple, MultipleHiddenInput … … 90 91 if formfield: 91 92 field_list.append((f.name, formfield)) 92 base_fields = SortedDict FromList(field_list)93 base_fields = SortedDict(field_list) 93 94 return type(opts.object_name + 'Form', (form,), 94 95 {'base_fields': base_fields, '_model': model, … … 119 120 if formfield: 120 121 field_list.append((f.name, formfield)) 121 base_fields = SortedDict FromList(field_list)122 base_fields = SortedDict(field_list) 122 123 return type(opts.object_name + 'InstanceForm', (form,), 123 124 {'base_fields': base_fields, '_model': model, … … 128 129 Returns a Form class for the given list of Django database field instances. 129 130 """ 130 fields = SortedDict FromList([(f.name, f.formfield())131 for f in field_list if f.editable])131 fields = SortedDict([(f.name, f.formfield()) 132 for f in field_list if f.editable]) 132 133 return type('FormForFields', (BaseForm,), {'base_fields': fields}) 133 134
