mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-23 02:22:14 +03:00
adds backward compatibility
This commit is contained in:
parent
e4e3f57321
commit
47c61679a5
|
@ -30,6 +30,11 @@ from rest_framework.compat import (
|
|||
)
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
def is_simple_callable(obj):
|
||||
"""
|
||||
|
@ -224,7 +229,7 @@ class Field(object):
|
|||
return [self.to_native(item) for item in value]
|
||||
elif isinstance(value, dict):
|
||||
# Make sure we preserve field ordering, if it exists
|
||||
ret = collections.OrderedDict()
|
||||
ret = OrderedDict()
|
||||
for key, val in value.items():
|
||||
ret[key] = self.to_native(val)
|
||||
return ret
|
||||
|
@ -239,7 +244,7 @@ class Field(object):
|
|||
return {}
|
||||
|
||||
def metadata(self):
|
||||
metadata = collections.OrderedDict()
|
||||
metadata = OrderedDict()
|
||||
metadata['type'] = self.type_label
|
||||
metadata['required'] = getattr(self, 'required', False)
|
||||
optional_attrs = ['read_only', 'label', 'help_text',
|
||||
|
|
|
@ -16,7 +16,7 @@ For example, you might have a `urls.py` that looks something like this:
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import itertools
|
||||
from collections import namedtuple, OrderedDict
|
||||
from collections import namedtuple
|
||||
from django.conf.urls import patterns, url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
|
@ -25,6 +25,11 @@ from rest_framework.response import Response
|
|||
from rest_framework.reverse import reverse
|
||||
from rest_framework.urlpatterns import format_suffix_patterns
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs'])
|
||||
DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs'])
|
||||
|
|
|
@ -11,7 +11,6 @@ python primitives.
|
|||
response content is handled by parsers and renderers.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from collections import OrderedDict
|
||||
import copy
|
||||
import datetime
|
||||
import inspect
|
||||
|
@ -37,6 +36,11 @@ from rest_framework.settings import api_settings
|
|||
from rest_framework.relations import * # NOQA
|
||||
from rest_framework.fields import * # NOQA
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
def _resolve_model(obj):
|
||||
"""
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
Helper classes for parsers.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from collections import OrderedDict
|
||||
from django.utils import timezone
|
||||
from django.db.models.query import QuerySet
|
||||
from django.utils.functional import Promise
|
||||
|
@ -13,6 +12,11 @@ import decimal
|
|||
import types
|
||||
import json
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
"""
|
||||
|
|
|
@ -3,7 +3,6 @@ Provides an APIView class that is the base of all views in REST framework.
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from collections import OrderedDict
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import Http404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -14,6 +13,11 @@ from rest_framework.response import Response
|
|||
from rest_framework.settings import api_settings
|
||||
from rest_framework.utils import formatting
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
def get_view_name(view_cls, suffix=None):
|
||||
"""
|
||||
|
|
|
@ -3,7 +3,6 @@ General serializer field tests.
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from collections import OrderedDict
|
||||
import datetime
|
||||
import re
|
||||
from decimal import Decimal
|
||||
|
@ -14,6 +13,11 @@ from django.test import TestCase
|
|||
from rest_framework import serializers
|
||||
from tests.models import RESTFrameworkModel
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from django.utils.datastructures import SortedDict as OrderedDict
|
||||
|
||||
|
||||
class TimestampedModel(models.Model):
|
||||
added = models.DateTimeField(auto_now_add=True)
|
||||
|
|
Loading…
Reference in New Issue
Block a user