Skip to content

Commit

Permalink
chore: use re_path only when strictly necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Sep 9, 2020
1 parent dbefbbd commit 590c323
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
36 changes: 16 additions & 20 deletions mezzanine/blog/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import re_path
from django.urls import path, re_path

from mezzanine.blog import views
from mezzanine.conf import settings
Expand All @@ -9,36 +9,34 @@

# Blog patterns.
urlpatterns = [
re_path(
r"^feeds/(?P<format>.*)%s$" % _slash,
path(
"feeds/<format>" + _slash,
views.blog_post_feed,
name="blog_post_feed",
),
re_path(
r"^tag/(?P<tag>.*)/feeds/(?P<format>.*)%s$" % _slash,
path(
"tag/<tag>/feeds/<format>" + _slash,
views.blog_post_feed,
name="blog_post_feed_tag",
),
re_path(
r"^tag/(?P<tag>.*)%s$" % _slash, views.blog_post_list, name="blog_post_list_tag"
),
re_path(
r"^category/(?P<category>.*)/feeds/(?P<format>.*)%s$" % _slash,
path("tag/<tag>" + _slash, views.blog_post_list, name="blog_post_list_tag"),
path(
"category/<category>/feeds/<format>" + _slash,
views.blog_post_feed,
name="blog_post_feed_category",
),
re_path(
r"^category/(?P<category>.*)%s$" % _slash,
path(
"category/<category>" + _slash,
views.blog_post_list,
name="blog_post_list_category",
),
re_path(
r"^author/(?P<username>.*)/feeds/(?P<format>.*)%s$" % _slash,
path(
"author/<username>/feeds/<format>" + _slash,
views.blog_post_feed,
name="blog_post_feed_author",
),
re_path(
r"^author/(?P<username>.*)%s$" % _slash,
path(
"author/<username>" + _slash,
views.blog_post_list,
name="blog_post_list_author",
),
Expand Down Expand Up @@ -68,8 +66,6 @@
views.blog_post_detail,
name="blog_post_detail_year",
),
re_path(
r"^(?P<slug>.*)%s$" % _slash, views.blog_post_detail, name="blog_post_detail"
),
re_path(r"^$", views.blog_post_list, name="blog_post_list"),
path("<slug>" + _slash, views.blog_post_detail, name="blog_post_detail"),
path("", views.blog_post_list, name="blog_post_list"),
]
6 changes: 3 additions & 3 deletions mezzanine/pages/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import re_path
from django.urls import path
from django.conf import settings

from mezzanine.pages import page_processors, views
Expand All @@ -9,8 +9,8 @@

# Page patterns.
urlpatterns = [
re_path(
"(?P<slug>.*)%s$" % ("/" if settings.APPEND_SLASH else ""),
path(
"<path:slug>" + ("/" if settings.APPEND_SLASH else ""),
views.page,
name="page",
),
Expand Down
4 changes: 2 additions & 2 deletions mezzanine/project_template/project_name/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.urls import path, include, re_path
from django.urls import path, include
from django.views.i18n import set_language
from django.views.generic import TemplateView

Expand All @@ -23,7 +23,7 @@

if settings.USE_MODELTRANSLATION:
urlpatterns += [
re_path("^i18n/$", set_language, name="set_language"),
path("i18n", set_language, name="set_language"),
]

urlpatterns += [
Expand Down
6 changes: 3 additions & 3 deletions mezzanine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Return a robots.txt that disallows all spiders when DEBUG is True.
if getattr(settings, "DEBUG", False):
urlpatterns += [
re_path(
path(
"robots.txt",
lambda r: HttpResponse(
"User-agent: *\nDisallow: /", content_type="text/plain"
Expand Down Expand Up @@ -70,7 +70,7 @@
if BLOG_SLUG:
BLOG_SLUG += "/"
blog_patterns = [
re_path(r"^%s" % BLOG_SLUG, include("mezzanine.blog.urls")),
path(BLOG_SLUG, include("mezzanine.blog.urls")),
]
urlpatterns += blog_patterns

Expand All @@ -84,7 +84,7 @@
PAGES_SLUG = str(getattr(settings, "PAGES_SLUG", "pages").strip("/") + "/")
blog_patterns_start = urlpatterns.index(blog_patterns[0])
urlpatterns[blog_patterns_start : len(blog_patterns)] = [
re_path(r"^%s" % PAGES_SLUG, include("mezzanine.pages.urls")),
path(PAGES_SLUG, include("mezzanine.pages.urls")),
]
else:
urlpatterns += [
Expand Down

0 comments on commit 590c323

Please sign in to comment.