aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils
diff options
context:
space:
mode:
authorTom Christie2014-11-06 12:00:30 +0000
committerTom Christie2014-11-06 12:00:30 +0000
commit4e001dbb7ac0bc13d6d5fbb4524e905184610aa2 (patch)
treef653aa5d1e0eaff780ba52039f29085e4bc8f54c /rest_framework/utils
parent9923a6ce9013693ea1723e7895b3cab638d719fd (diff)
downloaddjango-rest-framework-4e001dbb7ac0bc13d6d5fbb4524e905184610aa2.tar.bz2
Drop usage of SortedDict. Closes #2027.
Diffstat (limited to 'rest_framework/utils')
-rw-r--r--rest_framework/utils/encoders.py11
-rw-r--r--rest_framework/utils/model_meta.py12
2 files changed, 11 insertions, 12 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index 486186c9..4d6bb3a3 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -4,9 +4,8 @@ Helper classes for parsers.
from __future__ import unicode_literals
from django.db.models.query import QuerySet
from django.utils import six, timezone
-from django.utils.datastructures import SortedDict
from django.utils.functional import Promise
-from rest_framework.compat import force_text
+from rest_framework.compat import force_text, OrderedDict
import datetime
import decimal
import types
@@ -68,7 +67,7 @@ else:
class SafeDumper(yaml.SafeDumper):
"""
Handles decimals as strings.
- Handles SortedDicts as usual dicts, but preserves field order, rather
+ Handles OrderedDicts as usual dicts, but preserves field order, rather
than the usual behaviour of sorting the keys.
"""
def represent_decimal(self, data):
@@ -82,7 +81,7 @@ else:
best_style = True
if hasattr(mapping, 'items'):
mapping = list(mapping.items())
- if not isinstance(mapping, SortedDict):
+ if not isinstance(mapping, OrderedDict):
mapping.sort()
for item_key, item_value in mapping:
node_key = self.represent_data(item_key)
@@ -104,7 +103,7 @@ else:
SafeDumper.represent_decimal
)
SafeDumper.add_representer(
- SortedDict,
+ OrderedDict,
yaml.representer.SafeRepresenter.represent_dict
)
# SafeDumper.add_representer(
@@ -112,7 +111,7 @@ else:
# yaml.representer.SafeRepresenter.represent_dict
# )
# SafeDumper.add_representer(
- # SortedDictWithMetadata,
+ # OrderedDictWithMetadata,
# yaml.representer.SafeRepresenter.represent_dict
# )
SafeDumper.add_representer(
diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py
index 7a95bcdd..82361edf 100644
--- a/rest_framework/utils/model_meta.py
+++ b/rest_framework/utils/model_meta.py
@@ -8,7 +8,7 @@ Usage: `get_field_info(model)` returns a `FieldInfo` instance.
from collections import namedtuple
from django.db import models
from django.utils import six
-from django.utils.datastructures import SortedDict
+from rest_framework.compat import OrderedDict
import inspect
@@ -63,12 +63,12 @@ def get_field_info(model):
pk = pk.rel.to._meta.pk
# Deal with regular fields.
- fields = SortedDict()
+ fields = OrderedDict()
for field in [field for field in opts.fields if field.serialize and not field.rel]:
fields[field.name] = field
# Deal with forward relationships.
- forward_relations = SortedDict()
+ forward_relations = OrderedDict()
for field in [field for field in opts.fields if field.serialize and field.rel]:
forward_relations[field.name] = RelationInfo(
model_field=field,
@@ -89,7 +89,7 @@ def get_field_info(model):
)
# Deal with reverse relationships.
- reverse_relations = SortedDict()
+ reverse_relations = OrderedDict()
for relation in opts.get_all_related_objects():
accessor_name = relation.get_accessor_name()
reverse_relations[accessor_name] = RelationInfo(
@@ -114,14 +114,14 @@ def get_field_info(model):
# Shortcut that merges both regular fields and the pk,
# for simplifying regular field lookup.
- fields_and_pk = SortedDict()
+ fields_and_pk = OrderedDict()
fields_and_pk['pk'] = pk
fields_and_pk[pk.name] = pk
fields_and_pk.update(fields)
# Shortcut that merges both forward and reverse relationships
- relations = SortedDict(
+ relations = OrderedDict(
list(forward_relations.items()) +
list(reverse_relations.items())
)