Commit 21bac854 by kazmiruk

move compatibility checks into compat.py

parent 1116a534
...@@ -265,3 +265,13 @@ except ImportError: ...@@ -265,3 +265,13 @@ except ImportError:
klass.__unicode__ = klass.__str__ klass.__unicode__ = klass.__str__
klass.__str__ = lambda self: self.__unicode__().encode('utf-8') klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass 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
...@@ -25,16 +25,11 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -25,16 +25,11 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.dateparse import parse_date, parse_datetime, parse_time from django.utils.dateparse import parse_date, parse_datetime, parse_time
from rest_framework import ISO_8601 from rest_framework import ISO_8601
from rest_framework.compat import ( from rest_framework.compat import (
BytesIO, smart_text, BytesIO, smart_text, OrderedDict,
force_text, is_non_str_iterable force_text, is_non_str_iterable
) )
from rest_framework.settings import api_settings 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): def is_simple_callable(obj):
""" """
......
...@@ -21,15 +21,11 @@ from django.conf.urls import patterns, url ...@@ -21,15 +21,11 @@ from django.conf.urls import patterns, url
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
from rest_framework import views from rest_framework import views
from rest_framework.compat import OrderedDict
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns 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']) Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs'])
DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs']) DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs'])
......
...@@ -23,6 +23,7 @@ from django.forms import widgets ...@@ -23,6 +23,7 @@ from django.forms import widgets
from django.utils import six from django.utils import six
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from rest_framework.compat import OrderedDict, GenericForeignKey
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
...@@ -36,16 +37,6 @@ 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.relations import * # NOQA
from rest_framework.fields 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): def _resolve_model(obj):
""" """
......
...@@ -5,18 +5,13 @@ from __future__ import unicode_literals ...@@ -5,18 +5,13 @@ from __future__ import unicode_literals
from django.utils import timezone from django.utils import timezone
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.utils.functional import Promise 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 from rest_framework.serializers import DictWithMetadata, OrderedDictWithMetadata
import datetime import datetime
import decimal import decimal
import types import types
import json import json
try:
from collections import OrderedDict
except ImportError:
from django.utils.datastructures import SortedDict as OrderedDict
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
""" """
......
...@@ -7,17 +7,12 @@ from django.core.exceptions import PermissionDenied ...@@ -7,17 +7,12 @@ from django.core.exceptions import PermissionDenied
from django.http import Http404 from django.http import Http404
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from rest_framework import status, exceptions 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.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils import formatting 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): def get_view_name(view_cls, suffix=None):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment