Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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. authored November 11, 2007
18  django/newforms/forms.py
@@ -2,7 +2,7 @@
2 2
 Form classes
3 3
 """
4 4
 
5  
-import copy
  5
+from copy import deepcopy
6 6
 
7 7
 from django.utils.datastructures import SortedDict
8 8
 from django.utils.html import escape
@@ -21,18 +21,6 @@ def pretty_name(name):
21 21
     name = name[0].upper() + name[1:]
22 22
     return name.replace('_', ' ')
23 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, because
27  
-    # 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  
-
36 24
 class DeclarativeFieldsMetaclass(type):
37 25
     """
38 26
     Metaclass that converts Field attributes to a dictionary called
@@ -49,7 +37,7 @@ def __new__(cls, name, bases, attrs):
49 37
             if hasattr(base, 'base_fields'):
50 38
                 fields = base.base_fields.items() + fields
51 39
 
52  
-        attrs['base_fields'] = SortedDictFromList(fields)
  40
+        attrs['base_fields'] = SortedDict(fields)
53 41
         return type.__new__(cls, name, bases, attrs)
54 42
 
55 43
 class BaseForm(StrAndUnicode):
@@ -74,7 +62,7 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
74 62
         # alter self.fields, we create self.fields here by copying base_fields.
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):
80 68
         return self.as_table()
11  django/newforms/models.py
@@ -5,9 +5,10 @@
5 5
 
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, SortedDictFromList
  11
+from forms import BaseForm
11 12
 from fields import Field, ChoiceField
12 13
 from widgets import Select, SelectMultiple, MultipleHiddenInput
13 14
 
@@ -89,7 +90,7 @@ def form_for_model(model, form=BaseForm, fields=None,
89 90
         formfield = formfield_callback(f)
90 91
         if formfield:
91 92
             field_list.append((f.name, formfield))
92  
-    base_fields = SortedDictFromList(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,
95 96
          'save': make_model_save(model, fields, 'created')})
@@ -118,7 +119,7 @@ def form_for_instance(instance, form=BaseForm, fields=None,
118 119
         formfield = formfield_callback(f, initial=current_value)
119 120
         if formfield:
120 121
             field_list.append((f.name, formfield))
121  
-    base_fields = SortedDictFromList(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,
124 125
          'save': make_instance_save(instance, fields, 'changed')})
@@ -127,8 +128,8 @@ def form_for_fields(field_list):
127 128
     """
128 129
     Returns a Form class for the given list of Django database field instances.
129 130
     """
130  
-    fields = SortedDictFromList([(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
 
134 135
 class QuerySetIterator(object):

0 notes on commit a4907be

Please sign in to comment.
Something went wrong with that request. Please try again.