Fixed #5918 -- Removed `SortedDictFromList` since `SortedDict` now can do everything `SortedDictFromList` could do. Since `SortedDict`'s `copy` method doesn't return a deepcopy as `SortedDictFromList`'s `copy` method did, you will need to update your code if you were relying on `SortedDictFromList.copy` to return a deepcopy by using the `deepcopy` function from the `copy` module.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6668 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
af256a02f9
commit
a4907be38e
|
@ -2,7 +2,7 @@
|
|||
Form classes
|
||||
"""
|
||||
|
||||
import copy
|
||||
from copy import deepcopy
|
||||
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.html import escape
|
||||
|
@ -21,18 +21,6 @@ def pretty_name(name):
|
|||
name = name[0].upper() + name[1:]
|
||||
return name.replace('_', ' ')
|
||||
|
||||
class SortedDictFromList(SortedDict):
|
||||
"A dictionary that keeps its keys in the order in which they're inserted."
|
||||
# This is different than django.utils.datastructures.SortedDict, because
|
||||
# this takes a list/tuple as the argument to __init__().
|
||||
def __init__(self, data=None):
|
||||
if data is None: data = []
|
||||
self.keyOrder = [d[0] for d in data]
|
||||
dict.__init__(self, dict(data))
|
||||
|
||||
def copy(self):
|
||||
return SortedDictFromList([(k, copy.deepcopy(v)) for k, v in self.items()])
|
||||
|
||||
class DeclarativeFieldsMetaclass(type):
|
||||
"""
|
||||
Metaclass that converts Field attributes to a dictionary called
|
||||
|
@ -49,7 +37,7 @@ class DeclarativeFieldsMetaclass(type):
|
|||
if hasattr(base, 'base_fields'):
|
||||
fields = base.base_fields.items() + fields
|
||||
|
||||
attrs['base_fields'] = SortedDictFromList(fields)
|
||||
attrs['base_fields'] = SortedDict(fields)
|
||||
return type.__new__(cls, name, bases, attrs)
|
||||
|
||||
class BaseForm(StrAndUnicode):
|
||||
|
@ -74,7 +62,7 @@ class BaseForm(StrAndUnicode):
|
|||
# alter self.fields, we create self.fields here by copying base_fields.
|
||||
# Instances should always modify self.fields; they should not modify
|
||||
# self.base_fields.
|
||||
self.fields = self.base_fields.copy()
|
||||
self.fields = deepcopy(self.base_fields)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.as_table()
|
||||
|
|
|
@ -5,9 +5,10 @@ and database field objects.
|
|||
|
||||
from django.utils.translation import ugettext
|
||||
from django.utils.encoding import smart_unicode
|
||||
from django.utils.datastructures import SortedDict
|
||||
|
||||
from util import ValidationError
|
||||
from forms import BaseForm, SortedDictFromList
|
||||
from forms import BaseForm
|
||||
from fields import Field, ChoiceField
|
||||
from widgets import Select, SelectMultiple, MultipleHiddenInput
|
||||
|
||||
|
@ -89,7 +90,7 @@ def form_for_model(model, form=BaseForm, fields=None,
|
|||
formfield = formfield_callback(f)
|
||||
if formfield:
|
||||
field_list.append((f.name, formfield))
|
||||
base_fields = SortedDictFromList(field_list)
|
||||
base_fields = SortedDict(field_list)
|
||||
return type(opts.object_name + 'Form', (form,),
|
||||
{'base_fields': base_fields, '_model': model,
|
||||
'save': make_model_save(model, fields, 'created')})
|
||||
|
@ -118,7 +119,7 @@ def form_for_instance(instance, form=BaseForm, fields=None,
|
|||
formfield = formfield_callback(f, initial=current_value)
|
||||
if formfield:
|
||||
field_list.append((f.name, formfield))
|
||||
base_fields = SortedDictFromList(field_list)
|
||||
base_fields = SortedDict(field_list)
|
||||
return type(opts.object_name + 'InstanceForm', (form,),
|
||||
{'base_fields': base_fields, '_model': model,
|
||||
'save': make_instance_save(instance, fields, 'changed')})
|
||||
|
@ -127,8 +128,8 @@ def form_for_fields(field_list):
|
|||
"""
|
||||
Returns a Form class for the given list of Django database field instances.
|
||||
"""
|
||||
fields = SortedDictFromList([(f.name, f.formfield())
|
||||
for f in field_list if f.editable])
|
||||
fields = SortedDict([(f.name, f.formfield())
|
||||
for f in field_list if f.editable])
|
||||
return type('FormForFields', (BaseForm,), {'base_fields': fields})
|
||||
|
||||
class QuerySetIterator(object):
|
||||
|
|
Loading…
Reference in New Issue