Commit 3001b56e by Mariusz Felisiak Committed by Tom Christie

Fixed Django 2.0 compatibility due to `django.conf.urls.include` parameters change. (#4866)

parent 31e9f7df
...@@ -307,3 +307,10 @@ def set_many(instance, field, value): ...@@ -307,3 +307,10 @@ def set_many(instance, field, value):
else: else:
field = getattr(instance, field) field = getattr(instance, field)
field.set(value) field.set(value)
def include(module, namespace=None, app_name=None):
from django.conf.urls import include
if django.VERSION < (1,9):
return include(module, namespace, app_name)
else:
return include((module, app_name), namespace)
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import include, url from django.conf.urls import url
from rest_framework.compat import RegexURLResolver from rest_framework.compat import RegexURLResolver, include
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
......
...@@ -4,12 +4,13 @@ import json ...@@ -4,12 +4,13 @@ import json
from collections import namedtuple from collections import namedtuple
import pytest import pytest
from django.conf.urls import include, url from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from rest_framework import permissions, serializers, viewsets from rest_framework import permissions, serializers, viewsets
from rest_framework.compat import include
from rest_framework.decorators import detail_route, list_route from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.routers import DefaultRouter, SimpleRouter from rest_framework.routers import DefaultRouter, SimpleRouter
...@@ -81,7 +82,7 @@ empty_prefix_urls = [ ...@@ -81,7 +82,7 @@ empty_prefix_urls = [
urlpatterns = [ urlpatterns = [
url(r'^non-namespaced/', include(namespaced_router.urls)), url(r'^non-namespaced/', include(namespaced_router.urls)),
url(r'^namespaced/', include(namespaced_router.urls, namespace='example')), url(r'^namespaced/', include(namespaced_router.urls, namespace='example', app_name='example')),
url(r'^example/', include(notes_router.urls)), url(r'^example/', include(notes_router.urls)),
url(r'^example2/', include(kwarged_notes_router.urls)), url(r'^example2/', include(kwarged_notes_router.urls)),
......
import pytest import pytest
from django.conf.urls import include, url from django.conf.urls import url
from django.test import override_settings from django.test import override_settings
from rest_framework import serializers, status, versioning from rest_framework import serializers, status, versioning
from rest_framework.compat import include
from rest_framework.decorators import APIView from rest_framework.decorators import APIView
from rest_framework.relations import PKOnlyObject from rest_framework.relations import PKOnlyObject
from rest_framework.response import Response from rest_framework.response import Response
...@@ -170,7 +171,7 @@ class TestURLReversing(URLPatternsTestCase): ...@@ -170,7 +171,7 @@ class TestURLReversing(URLPatternsTestCase):
] ]
urlpatterns = [ urlpatterns = [
url(r'^v1/', include(included, namespace='v1')), url(r'^v1/', include(included, namespace='v1', app_name='v1')),
url(r'^another/$', dummy_view, name='another'), url(r'^another/$', dummy_view, name='another'),
url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'), url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
] ]
...@@ -335,8 +336,8 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase): ...@@ -335,8 +336,8 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase):
] ]
urlpatterns = [ urlpatterns = [
url(r'^v1/', include(included, namespace='v1')), url(r'^v1/', include(included, namespace='v1', app_name='v1')),
url(r'^v2/', include(included, namespace='v2')) url(r'^v2/', include(included, namespace='v2', app_name='v2'))
] ]
def setUp(self): def setUp(self):
...@@ -367,7 +368,7 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase): ...@@ -367,7 +368,7 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase):
] ]
included = [ included = [
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'), url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
url(r'^nested/', include(nested, namespace='nested-namespace')) url(r'^nested/', include(nested, namespace='nested-namespace', app_name='nested-namespace'))
] ]
urlpatterns = [ urlpatterns = [
......
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