Skip to content

Commit

Permalink
Use path/re_path instead of url to squelch Django 4.0 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
axnsan12 committed Oct 25, 2020
1 parent a9ec562 commit aae2717
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 76 deletions.
4 changes: 2 additions & 2 deletions testproj/articles/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import path, include
from rest_framework.routers import SimpleRouter

from articles import views
Expand All @@ -7,5 +7,5 @@
router.register('', views.ArticleViewSet)

urlpatterns = [
url(r'^', include(router.urls)),
path('', include(router.urls)),
]
10 changes: 5 additions & 5 deletions testproj/people/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path

from .views import IdentityViewSet, PersonViewSet

Expand All @@ -18,9 +18,9 @@
})

urlpatterns = (
url(r'^$', person_list, name='people-list'),
url(r'^(?P<pk>[0-9]+)$', person_detail, name='person-detail'),
path('', person_list, name='people-list'),
path('<int:pk>', person_detail, name='person-detail'),

url(r'^(?P<person>[0-9]+)/identity$', identity_detail,
name='person-identity'),
path('<int:person>/identity$', identity_detail,
name='person-identity'),
)
23 changes: 6 additions & 17 deletions testproj/snippets/urls.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import django

from . import views

if django.VERSION[:2] >= (2, 0):
from django.urls import path

urlpatterns = [
path('', views.SnippetList.as_view()),
path('<int:pk>/', views.SnippetDetail.as_view()),
path('views/<int:snippet_pk>/', views.SnippetViewerList.as_view()),
]
else:
from django.conf.urls import url
from django.urls import path

urlpatterns = [
url('^$', views.SnippetList.as_view()),
url(r'^(?P<pk>\d+)/$', views.SnippetDetail.as_view()),
url(r'^views/(?P<snippet_pk>\d+)/$', views.SnippetViewerList.as_view()),
]
urlpatterns = [
path('', views.SnippetList.as_view()),
path('<int:pk>/', views.SnippetDetail.as_view()),
path('views/<int:snippet_pk>/', views.SnippetViewerList.as_view()),
]
1 change: 1 addition & 0 deletions testproj/testproj/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'oauth2_provider',
'corsheaders',

Expand Down
44 changes: 23 additions & 21 deletions testproj/testproj/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import user_agents
from django.conf.urls import include, url
from django.contrib import admin
from django.shortcuts import redirect
from django.urls import path, re_path, include
from rest_framework import permissions
from rest_framework.decorators import api_view

Expand Down Expand Up @@ -49,26 +49,28 @@ def root_redirect(request):

# urlpatterns required for settings values
required_urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
path('admin/', admin.site.urls),
path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]

urlpatterns = [
url(r'^swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
url(r'^redoc-old/$', SchemaView.with_ui('redoc-old', cache_timeout=0), name='schema-redoc-old'),

url(r'^cached/swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=None), name='cschema-json'),
url(r'^cached/swagger/$', SchemaView.with_ui('swagger', cache_timeout=None), name='cschema-swagger-ui'),
url(r'^cached/redoc/$', SchemaView.with_ui('redoc', cache_timeout=None), name='cschema-redoc'),

url(r'^$', root_redirect),

url(r'^snippets/', include('snippets.urls')),
url(r'^articles/', include('articles.urls')),
url(r'^users/', include('users.urls')),
url(r'^todo/', include('todo.urls')),
url(r'^people/', include('people.urls')),
url(r'^plain/', plain_view),
] + required_urlpatterns
re_path(r'^swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0),
name='schema-json'),
path('swagger/', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('redoc-old/', SchemaView.with_ui('redoc-old', cache_timeout=0), name='schema-redoc-old'),

re_path(r'^cached/swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=None),
name='cschema-json'),
path('cached/swagger/', SchemaView.with_ui('swagger', cache_timeout=None), name='cschema-swagger-ui'),
path('cached/redoc/', SchemaView.with_ui('redoc', cache_timeout=None), name='cschema-redoc'),

path('', root_redirect),

path('snippets/', include('snippets.urls')),
path('articles/', include('articles.urls')),
path('users/', include('users.urls')),
path('todo/', include('todo.urls')),
path('people/', include('people.urls')),
path('plain/', plain_view),
] + required_urlpatterns
6 changes: 3 additions & 3 deletions testproj/todo/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path
from rest_framework import routers

from todo import views
Expand All @@ -14,6 +14,6 @@
urlpatterns = router.urls

urlpatterns += [
url(r'^(?P<todo_id>\d+)/yetanothers/(?P<yetanother_id>\d+)/$',
views.NestedTodoView.as_view(), ),
path(r'<int:todo_id>/yetanothers/<int:yetanother_id>/$',
views.NestedTodoView.as_view(), ),
]
6 changes: 3 additions & 3 deletions testproj/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf.urls import url
from django.urls import path

from users import views

urlpatterns = [
url(r'^$', views.UserList.as_view()),
url(r'^(?P<pk>\d+)/$', views.user_detail),
path('', views.UserList.as_view()),
path('<int:pk>/', views.user_detail),
]
4 changes: 2 additions & 2 deletions tests/test_form_parameters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from django.conf.urls import url
from django.urls import path
from django.utils.decorators import method_decorator
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.settings import api_settings
Expand Down Expand Up @@ -32,7 +32,7 @@ class CustomObtainAuthToken(ObtainAuthToken):
throttle_classes = api_settings.DEFAULT_THROTTLE_CLASSES

urlpatterns = [
url(r'token/$', CustomObtainAuthToken.as_view()),
path('token/', CustomObtainAuthToken.as_view()),
]

generator = OpenAPISchemaGenerator(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_schema_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from collections import OrderedDict

import pytest
from django.conf.urls import url
from django.contrib.postgres import fields as postgres_fields
from django.db import models
from django.urls import path
from django.utils.inspect import get_func_args
from django_fake_model import models as fake_models
from rest_framework import routers, serializers, viewsets
Expand Down Expand Up @@ -148,8 +148,8 @@ def test_view(request, pk=None):
return Response({"message": "Hello, world!"})

patterns = [
url(r'^/test/$', test_override),
url(r'^/test/$', test_view),
path('test/', test_override),
path('test/', test_view),
]

generator = OpenAPISchemaGenerator(
Expand Down
6 changes: 3 additions & 3 deletions tests/urlconfs/login_test_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path

from testproj.urls import required_urlpatterns

Expand All @@ -8,6 +8,6 @@ def dummy(request):


urlpatterns = required_urlpatterns + [
url(r'^test/login$', dummy, name='login'),
url(r'^test/logout$', dummy, name='logout'),
path('test/login', dummy, name='login'),
path('test/logout', dummy, name='logout'),
]
6 changes: 3 additions & 3 deletions tests/urlconfs/non_public_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import path, include
from rest_framework import permissions

import testproj.urls
Expand All @@ -13,6 +13,6 @@
view = view.without_ui(cache_timeout=None)

urlpatterns = [
url(r'^', include(testproj.urls)),
url(r'^private/swagger.yaml', view, name='schema-private'),
path('', include(testproj.urls)),
path('private/swagger.yaml', view, name='schema-private'),
]
4 changes: 2 additions & 2 deletions tests/urlconfs/ns_version1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path
from rest_framework import generics, versioning

from snippets.models import Snippet
Expand All @@ -23,5 +23,5 @@ def post(self, request, *args, **kwargs):
app_name = 'test_ns_versioning'

urlpatterns = required_urlpatterns + [
url(r"^$", SnippetList.as_view())
path("", SnippetList.as_view())
]
4 changes: 2 additions & 2 deletions tests/urlconfs/ns_version2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path
from rest_framework import fields

from snippets.serializers import SnippetSerializer
Expand All @@ -21,5 +21,5 @@ class SnippetListV2(SnippetListV1):
app_name = '2.0'

urlpatterns = required_urlpatterns + [
url(r"^$", SnippetListV2.as_view())
path("", SnippetListV2.as_view())
]
14 changes: 7 additions & 7 deletions tests/urlconfs/ns_versioning.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from django.conf.urls import include, url
from django.urls import path, re_path, include
from rest_framework import versioning

from testproj.urls import SchemaView, required_urlpatterns

from . import ns_version1, ns_version2

VERSION_PREFIX_NS = r"^versioned/ns/"
VERSION_PREFIX_NS = r"versioned/ns/"


class VersionedSchemaView(SchemaView):
versioning_class = versioning.NamespaceVersioning


schema_patterns = [
url(r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='ns-schema')
re_path(r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='ns-schema')
]


urlpatterns = required_urlpatterns + [
url(VERSION_PREFIX_NS + r"v1.0/snippets/", include(ns_version1, namespace='1.0')),
url(VERSION_PREFIX_NS + r"v2.0/snippets/", include(ns_version2)),
url(VERSION_PREFIX_NS + r'v1.0/', include((schema_patterns, '1.0'))),
url(VERSION_PREFIX_NS + r'v2.0/', include((schema_patterns, '2.0'))),
path(VERSION_PREFIX_NS + "v1.0/snippets/", include(ns_version1, namespace='1.0')),
path(VERSION_PREFIX_NS + "v2.0/snippets/", include(ns_version2)),
path(VERSION_PREFIX_NS + "v1.0/", include((schema_patterns, '1.0'))),
path(VERSION_PREFIX_NS + "v2.0/", include((schema_patterns, '2.0'))),
]
6 changes: 3 additions & 3 deletions tests/urlconfs/url_versioning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path
from rest_framework import fields, generics, versioning

from snippets.models import Snippet
Expand Down Expand Up @@ -43,6 +43,6 @@ class VersionedSchemaView(SchemaView):


urlpatterns = required_urlpatterns + [
url(VERSION_PREFIX_URL + r"snippets/$", SnippetList.as_view()),
url(VERSION_PREFIX_URL + r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='vschema-json'),
re_path(VERSION_PREFIX_URL + r"snippets/$", SnippetList.as_view()),
re_path(VERSION_PREFIX_URL + r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='vschema-json'),
]

0 comments on commit aae2717

Please sign in to comment.