Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #5918 -- Removed `SortedDictFromList` since `SortedDict` now ca…

…n 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
  • Loading branch information...
commit a4907be38ecc9f6caf3d2a787a7046af3f8b9ceb 1 parent af256a0
Gary Wilson Jr. gdub authored
Showing with 9 additions and 20 deletions.
  1. +3 −15 django/newforms/forms.py
  2. +6 −5 django/newforms/models.py
18 django/newforms/forms.py
View
@@ -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 @@ def __new__(cls, name, bases, attrs):
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 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
# 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()
11 django/newforms/models.py
View
@@ -5,9 +5,10 @@
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):
Please sign in to comment.
Something went wrong with that request. Please try again.