Skip to content

Commit

Permalink
Merge pull request #180 from hapytex/improvement/modern-paths
Browse files Browse the repository at this point in the history
Modern paths
  • Loading branch information
meshy committed Sep 3, 2022
2 parents da86f4e + 9fb398f commit a89118b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cbv/shortcut_urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.urls import re_path
from django.urls import path

from cbv import views


urlpatterns = [
re_path(
r"(?P<klass>[a-zA-Z_-]+)/$",
path(
"<str:klass>/",
views.LatestKlassDetailView.as_view(),
name="klass-detail-shortcut",
),
Expand Down
31 changes: 15 additions & 16 deletions cbv/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,51 @@
django/1.41a
django/1.41a/core
django/1.41a/core/DjangoRuntimeWarning
"""

from django.urls import path, re_path, reverse_lazy
from django.urls import path, reverse_lazy
from django.views.generic import RedirectView

from cbv import views


urlpatterns = [
path("", RedirectView.as_view(url=reverse_lazy("home"))),
re_path(
r"^(?P<package>[\w-]+)/$",
path(
"<slug:package>/",
views.RedirectToLatestVersionView.as_view(),
{"url_name": "version-detail"},
),
re_path(
r"^(?P<package>[\w-]+)/latest/$",
path(
"<slug:package>/latest/",
views.RedirectToLatestVersionView.as_view(),
{"url_name": "version-detail"},
name="latest-version-detail",
),
re_path(
r"^(?P<package>[\w-]+)/(?P<version>[^/]+)/$",
path(
"<slug:package>/<str:version>/",
views.VersionDetailView.as_view(),
name="version-detail",
),
re_path(
r"^(?P<package>[\w-]+)/latest/(?P<module>[\w\.]+)/$",
path(
"<slug:package>/latest/<str:module>/",
views.RedirectToLatestVersionView.as_view(),
{"url_name": "module-detail"},
name="latest-module-detail",
),
re_path(
r"^(?P<package>[\w-]+)/(?P<version>[^/]+)/(?P<module>[\w\.]+)/$",
path(
"<slug:package>/<str:version>/<str:module>/",
views.ModuleDetailView.as_view(),
name="module-detail",
),
re_path(
r"^(?P<package>[\w-]+)/latest/(?P<module>[\w\.]+)/(?P<klass>[\w]+)/$",
path(
"<slug:package>/latest/<str:module>/<str:klass>/",
views.RedirectToLatestVersionView.as_view(),
{"url_name": "klass-detail"},
name="latest-klass-detail",
),
re_path(
r"^(?P<package>[\w-]+)/(?P<version>[^/]+)/(?P<module>[\w\.]+)/(?P<klass>[\w]+)/$",
path(
"<slug:package>/<str:version>/<str:module>/<str:klass>/",
views.KlassDetailView.as_view(),
name="klass-detail",
),
Expand Down
4 changes: 2 additions & 2 deletions inspector/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path, re_path
from django.urls import include, path
from django.views.generic import TemplateView

from cbv.views import HomeView, Sitemap
Expand All @@ -9,7 +9,7 @@
urlpatterns = [
path("", HomeView.as_view(), name="home"),
path("projects/", include("cbv.urls")),
re_path(r"^sitemap\.xml$", Sitemap.as_view(), name="sitemap"),
path("sitemap.xml", Sitemap.as_view(), name="sitemap"),
path("", include("cbv.shortcut_urls"), {"package": "Django"}),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Expand Down

0 comments on commit a89118b

Please sign in to comment.