move compatibility checks into compat.py

This commit is contained in:
kazmiruk 2015-04-22 20:52:33 +07:00
parent 1116a534d4
commit 21bac85489
6 changed files with 15 additions and 33 deletions

View File

@ -265,3 +265,13 @@ except ImportError:
klass.__unicode__ = klass.__str__
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass
try:
from collections import OrderedDict
except ImportError:
from django.utils.datastructures import SortedDict as OrderedDict
if django.VERSION >= (1, 8):
from django.contrib.contenttypes.fields import GenericForeignKey
else:
from django.contrib.contenttypes.generic import GenericForeignKey

View File

@ -25,16 +25,11 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from rest_framework import ISO_8601
from rest_framework.compat import (
BytesIO, smart_text,
BytesIO, smart_text, OrderedDict,
force_text, is_non_str_iterable
)
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):
"""

View File

@ -21,15 +21,11 @@ from django.conf.urls import patterns, url
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import NoReverseMatch
from rest_framework import views
from rest_framework.compat import OrderedDict
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'])

View File

@ -23,6 +23,7 @@ from django.forms import widgets
from django.utils import six
from django.utils.functional import cached_property
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.compat import OrderedDict, GenericForeignKey
from rest_framework.settings import api_settings
@ -36,16 +37,6 @@ 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
if django.VERSION >= (1, 8):
from django.contrib.contenttypes.fields import GenericForeignKey
else:
from django.contrib.contenttypes.generic import GenericForeignKey
def _resolve_model(obj):
"""

View File

@ -5,18 +5,13 @@ from __future__ import unicode_literals
from django.utils import timezone
from django.db.models.query import QuerySet
from django.utils.functional import Promise
from rest_framework.compat import force_text
from rest_framework.compat import force_text, OrderedDict
from rest_framework.serializers import DictWithMetadata, OrderedDictWithMetadata
import datetime
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):
"""

View File

@ -7,17 +7,12 @@ from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status, exceptions
from rest_framework.compat import smart_text, HttpResponseBase, View
from rest_framework.compat import smart_text, HttpResponseBase, OrderedDict, View
from rest_framework.request import Request
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):
"""