mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +03:00
Add django.core.urlresolvers compatibility
This commit is contained in:
parent
8609c9ca8c
commit
197b63ab85
|
@ -23,7 +23,7 @@ There's no requirement for you to use them, but if you do then the self-describi
|
|||
|
||||
**Signature:** `reverse(viewname, *args, **kwargs)`
|
||||
|
||||
Has the same behavior as [`django.core.urlresolvers.reverse`][reverse], except that it returns a fully qualified URL, using the request to determine the host and port.
|
||||
Has the same behavior as [`django.urls.reverse`][reverse], except that it returns a fully qualified URL, using the request to determine the host and port.
|
||||
|
||||
You should **include the request as a keyword argument** to the function, for example:
|
||||
|
||||
|
@ -44,7 +44,7 @@ You should **include the request as a keyword argument** to the function, for ex
|
|||
|
||||
**Signature:** `reverse_lazy(viewname, *args, **kwargs)`
|
||||
|
||||
Has the same behavior as [`django.core.urlresolvers.reverse_lazy`][reverse-lazy], except that it returns a fully qualified URL, using the request to determine the host and port.
|
||||
Has the same behavior as [`django.urls.reverse_lazy`][reverse-lazy], except that it returns a fully qualified URL, using the request to determine the host and port.
|
||||
|
||||
As with the `reverse` function, you should **include the request as a keyword argument** to the function, for example:
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ REST framework includes the following test case classes, that mirror the existin
|
|||
|
||||
You can use any of REST framework's test case classes as you would for the regular Django test case classes. The `self.client` attribute will be an `APIClient` instance.
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from myproject.apps.core.models import Account
|
||||
|
|
|
@ -23,6 +23,16 @@ except ImportError:
|
|||
from django.utils import importlib # Will be removed in Django 1.9
|
||||
|
||||
|
||||
try:
|
||||
from django.urls import (
|
||||
NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve
|
||||
)
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import ( # Will be removed in Django 2.0
|
||||
NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
import urlparse # Python 2.x
|
||||
except ImportError:
|
||||
|
|
|
@ -4,9 +4,6 @@ from __future__ import unicode_literals
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
||||
from django.core.urlresolvers import (
|
||||
NoReverseMatch, Resolver404, get_script_prefix, resolve
|
||||
)
|
||||
from django.db.models import Manager
|
||||
from django.db.models.query import QuerySet
|
||||
from django.utils import six
|
||||
|
@ -14,6 +11,9 @@ from django.utils.encoding import python_2_unicode_compatible, smart_text
|
|||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework.compat import (
|
||||
NoReverseMatch, Resolver404, get_script_prefix, resolve
|
||||
)
|
||||
from rest_framework.fields import (
|
||||
Field, empty, get_attribute, is_simple_callable, iter_options
|
||||
)
|
||||
|
|
|
@ -3,11 +3,11 @@ Provide urlresolver functions that return fully qualified URLs or view names
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.urlresolvers import reverse as django_reverse
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from django.utils import six
|
||||
from django.utils.functional import lazy
|
||||
|
||||
from rest_framework.compat import reverse as django_reverse
|
||||
from rest_framework.compat import NoReverseMatch
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.utils.urls import replace_query_param
|
||||
|
||||
|
@ -54,7 +54,7 @@ def reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra
|
|||
|
||||
def _reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra):
|
||||
"""
|
||||
Same as `django.core.urlresolvers.reverse`, but optionally takes a request
|
||||
Same as `django.urls.reverse`, but optionally takes a request
|
||||
and returns a fully qualified URL, using the request to get the base URL.
|
||||
"""
|
||||
if format is not None:
|
||||
|
|
|
@ -20,9 +20,9 @@ from collections import OrderedDict, namedtuple
|
|||
|
||||
from django.conf.urls import url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
|
||||
from rest_framework import exceptions, renderers, views
|
||||
from rest_framework.compat import NoReverseMatch
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework.schemas import SchemaGenerator
|
||||
|
|
|
@ -2,12 +2,13 @@ from importlib import import_module
|
|||
|
||||
from django.conf import settings
|
||||
from django.contrib.admindocs.views import simplify_regex
|
||||
from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from rest_framework import exceptions, serializers
|
||||
from rest_framework.compat import coreapi, uritemplate, urlparse
|
||||
from rest_framework.compat import (
|
||||
RegexURLPattern, RegexURLResolver, coreapi, uritemplate, urlparse
|
||||
)
|
||||
from rest_framework.request import clone_request
|
||||
from rest_framework.views import APIView
|
||||
|
||||
|
|
|
@ -3,14 +3,13 @@ from __future__ import absolute_import, unicode_literals
|
|||
import re
|
||||
|
||||
from django import template
|
||||
from django.core.urlresolvers import NoReverseMatch, reverse
|
||||
from django.template import loader
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text, iri_to_uri
|
||||
from django.utils.html import escape, format_html, smart_urlquote
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
|
||||
from rest_framework.compat import template_render
|
||||
from rest_framework.compat import NoReverseMatch, reverse, template_render
|
||||
from rest_framework.renderers import HTMLFormRenderer
|
||||
from rest_framework.utils.urls import replace_query_param
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import include, url
|
||||
from django.core.urlresolvers import RegexURLResolver
|
||||
|
||||
from rest_framework.compat import RegexURLResolver
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.urlresolvers import get_script_prefix, resolve
|
||||
from rest_framework.compat import get_script_prefix, resolve
|
||||
|
||||
|
||||
def get_breadcrumbs(url, request=None):
|
||||
|
|
|
@ -6,7 +6,6 @@ from decimal import Decimal
|
|||
|
||||
from django.conf.urls import url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
|
@ -14,7 +13,7 @@ from django.utils.dateparse import parse_date
|
|||
from django.utils.six.moves import reload_module
|
||||
|
||||
from rest_framework import filters, generics, serializers, status
|
||||
from rest_framework.compat import django_filters
|
||||
from rest_framework.compat import django_filters, reverse
|
||||
from rest_framework.test import APIRequestFactory
|
||||
|
||||
from .models import BaseFilterableItem, BasicModel, FilterableItem
|
||||
|
|
|
@ -4,7 +4,6 @@ import base64
|
|||
import unittest
|
||||
|
||||
from django.contrib.auth.models import Group, Permission, User
|
||||
from django.core.urlresolvers import ResolverMatch
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
|
||||
|
@ -12,7 +11,7 @@ from rest_framework import (
|
|||
HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers,
|
||||
status
|
||||
)
|
||||
from rest_framework.compat import guardian, set_many
|
||||
from rest_framework.compat import ResolverMatch, guardian, set_many
|
||||
from rest_framework.filters import DjangoObjectPermissionsFilter
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from rest_framework.test import APIRequestFactory
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from rest_framework.compat import NoReverseMatch
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework.test import APIRequestFactory
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ from __future__ import unicode_literals
|
|||
from collections import namedtuple
|
||||
|
||||
from django.conf.urls import include, url
|
||||
from django.core import urlresolvers
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework.compat import RegexURLResolver, Resolver404
|
||||
from rest_framework.test import APIRequestFactory
|
||||
from rest_framework.urlpatterns import format_suffix_patterns
|
||||
|
||||
|
@ -28,7 +28,7 @@ class FormatSuffixTests(TestCase):
|
|||
urlpatterns = format_suffix_patterns(urlpatterns)
|
||||
except Exception:
|
||||
self.fail("Failed to apply `format_suffix_patterns` on the supplied urlpatterns")
|
||||
resolver = urlresolvers.RegexURLResolver(r'^/', urlpatterns)
|
||||
resolver = RegexURLResolver(r'^/', urlpatterns)
|
||||
for test_path in test_paths:
|
||||
request = factory.get(test_path.path)
|
||||
try:
|
||||
|
@ -43,7 +43,7 @@ class FormatSuffixTests(TestCase):
|
|||
urlpatterns = format_suffix_patterns([
|
||||
url(r'^test/$', dummy_view),
|
||||
])
|
||||
resolver = urlresolvers.RegexURLResolver(r'^/', urlpatterns)
|
||||
resolver = RegexURLResolver(r'^/', urlpatterns)
|
||||
|
||||
test_paths = [
|
||||
(URLTestPath('/test.api', (), {'format': 'api'}), True),
|
||||
|
@ -55,7 +55,7 @@ class FormatSuffixTests(TestCase):
|
|||
request = factory.get(test_path.path)
|
||||
try:
|
||||
callback, callback_args, callback_kwargs = resolver.resolve(request.path_info)
|
||||
except urlresolvers.Resolver404:
|
||||
except Resolver404:
|
||||
callback, callback_args, callback_kwargs = (None, None, None)
|
||||
if not expected_resolved:
|
||||
assert callback is None
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from rest_framework.compat import NoReverseMatch
|
||||
|
||||
|
||||
class MockObject(object):
|
||||
|
|
Loading…
Reference in New Issue
Block a user