Django

Code

Changeset 6668

Show
Ignore:
Timestamp:
11/10/07 22:44:20 (2 years ago)
Author:
gwilson
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r6352 r6668  
    33""" 
    44 
    5 import copy 
     5from copy import deepcopy 
    66 
    77from django.utils.datastructures import SortedDict 
     
    2121    name = name[0].upper() + name[1:] 
    2222    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, 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()]) 
    3523 
    3624class DeclarativeFieldsMetaclass(type): 
     
    5038                fields = base.base_fields.items() + fields 
    5139 
    52         attrs['base_fields'] = SortedDictFromList(fields) 
     40        attrs['base_fields'] = SortedDict(fields) 
    5341        return type.__new__(cls, name, bases, attrs) 
    5442 
     
    7563        # Instances should always modify self.fields; they should not modify 
    7664        # self.base_fields. 
    77         self.fields = self.base_fields.copy(
     65        self.fields = deepcopy(self.base_fields
    7866 
    7967    def __unicode__(self): 
  • django/trunk/django/newforms/models.py

    r6627 r6668  
    66from django.utils.translation import ugettext 
    77from django.utils.encoding import smart_unicode 
     8from django.utils.datastructures import SortedDict 
    89 
    910from util import ValidationError 
    10 from forms import BaseForm, SortedDictFromList 
     11from forms import BaseForm 
    1112from fields import Field, ChoiceField 
    1213from widgets import Select, SelectMultiple, MultipleHiddenInput 
     
    9091        if formfield: 
    9192            field_list.append((f.name, formfield)) 
    92     base_fields = SortedDictFromList(field_list) 
     93    base_fields = SortedDict(field_list) 
    9394    return type(opts.object_name + 'Form', (form,), 
    9495        {'base_fields': base_fields, '_model': model, 
     
    119120        if formfield: 
    120121            field_list.append((f.name, formfield)) 
    121     base_fields = SortedDictFromList(field_list) 
     122    base_fields = SortedDict(field_list) 
    122123    return type(opts.object_name + 'InstanceForm', (form,), 
    123124        {'base_fields': base_fields, '_model': model, 
     
    128129    Returns a Form class for the given list of Django database field instances. 
    129130    """ 
    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]) 
    132133    return type('FormForFields', (BaseForm,), {'base_fields': fields}) 
    133134