Skip to content

Commit

Permalink
Replace deprecated url() with re_path()
Browse files Browse the repository at this point in the history
url() was deprecated in Django 3, and removed in Django 4.
  • Loading branch information
ivarnakken committed Jul 26, 2022
1 parent c945081 commit add93b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lego/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import include
from django.http import Http404, HttpResponseRedirect
from django.urls import resolve
from django.urls import re_path, resolve
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import RedirectView

Expand All @@ -22,9 +22,9 @@ def version_redirect(request, path):

app_name = "api"
urlpatterns = [
url(r"^v1/", include((v1.urls, "v1"), namespace="v1")),
url(
re_path(r"^v1/", include((v1.urls, "v1"), namespace="v1")),
re_path(
r"^$", RedirectView.as_view(url=f"/api/{settings.API_VERSION}/"), name="default"
),
url(r"^(.*)/$", version_redirect),
re_path(r"^(.*)/$", version_redirect),
]
8 changes: 4 additions & 4 deletions lego/apps/oauth/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import absolute_import

from django.conf.urls import url
from django.urls import re_path

from oauth2_provider import views

from .views import LegoAuthorizationView

urlpatterns = (
url(r"^authorize/$", LegoAuthorizationView.as_view(), name="authorize"),
url(r"^token/$", views.TokenView.as_view(), name="token"),
url(r"^revoke_token/$", views.RevokeTokenView.as_view(), name="revoke-token"),
re_path(r"^authorize/$", LegoAuthorizationView.as_view(), name="authorize"),
re_path(r"^token/$", views.TokenView.as_view(), name="token"),
re_path(r"^revoke_token/$", views.RevokeTokenView.as_view(), name="revoke-token"),
)
4 changes: 2 additions & 2 deletions lego/apps/websockets/routing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import url
from django.urls import re_path

from channels.routing import ProtocolTypeRouter, URLRouter
from structlog import get_logger
Expand All @@ -26,7 +26,7 @@ async def __call__(self, scope):

protocols = {
"websocket": JWTAuthenticationMiddleware(
URLRouter([url("^$", GroupConsumer.as_asgi())])
URLRouter([re_path("^$", GroupConsumer.as_asgi())])
)
}

Expand Down
30 changes: 16 additions & 14 deletions lego/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import include
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path
from django.urls import path, re_path
from django.views.generic import TemplateView
from rest_framework.documentation import include_docs_urls

Expand All @@ -14,27 +14,27 @@
from lego.api.urls import urlpatterns as api

jwt_urlpatterns = [
url(r"^token-auth/$", obtain_jwt_token, name="obtain_jwt_token"),
url(r"^token-auth/refresh/$", refresh_jwt_token, name="refresh_jwt_token"),
url(r"^token-auth/verify/$", verify_jwt_token, name="verify_jwt_token"),
re_path(r"^token-auth/$", obtain_jwt_token, name="obtain_jwt_token"),
re_path(r"^token-auth/refresh/$", refresh_jwt_token, name="refresh_jwt_token"),
re_path(r"^token-auth/verify/$", verify_jwt_token, name="verify_jwt_token"),
]

authorization_urlpatterns = [
url(r"^oauth2/", include("lego.apps.oauth.urls")),
url(r"", include((jwt_urlpatterns, "jwt"), namespace="jwt")),
url(
re_path(r"^oauth2/", include("lego.apps.oauth.urls")),
re_path(r"", include((jwt_urlpatterns, "jwt"), namespace="jwt")),
re_path(
r"^login/",
LoginView.as_view(template_name="authorization/login.html"),
name="login",
),
url(r"^logout/", LogoutView.as_view(next_page="/"), name="logout"),
re_path(r"^logout/", LogoutView.as_view(next_page="/"), name="logout"),
]

urlpatterns = [
url(r"^api/", include("lego.api.urls", namespace="api")),
url(r"^authorization/", include(authorization_urlpatterns)),
url(r"^health/", include("health_check.urls")),
url(
re_path(r"^api/", include("lego.api.urls", namespace="api")),
re_path(r"^authorization/", include(authorization_urlpatterns)),
re_path(r"^health/", include("health_check.urls")),
re_path(
r"^api-docs/",
include_docs_urls( # type: ignore
title=settings.SITE["name"],
Expand All @@ -43,7 +43,9 @@
schema_url="/api",
),
),
url(r"^$", TemplateView.as_view(template_name="landing.html"), name="landing_page"),
re_path(
r"^$", TemplateView.as_view(template_name="landing.html"), name="landing_page"
),
]

if "debug_toolbar" in settings.INSTALLED_APPS:
Expand Down

0 comments on commit add93b1

Please sign in to comment.