Skip to content

Commit 709f582

Browse files
committed
Change the code to use the root middleware
1 parent 51e088f commit 709f582

File tree

8 files changed

+22
-46
lines changed

8 files changed

+22
-46
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: ".yarn/|yarn.lock"
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.1.0
4+
rev: v4.4.0
55
hooks:
66
- id: check-added-large-files
77
- id: check-merge-conflict
@@ -16,31 +16,31 @@ repos:
1616
language: system
1717
always_run: true
1818
- repo: https://github.com/asottile/pyupgrade
19-
rev: v2.31.0
19+
rev: v3.13.0
2020
hooks:
2121
- id: pyupgrade
2222
args: [--py38-plus]
2323
- repo: https://github.com/adamchainz/django-upgrade
24-
rev: 1.4.0
24+
rev: 1.15.0
2525
hooks:
2626
- id: django-upgrade
2727
args: [--target-version, "3.2"]
2828
- repo: https://github.com/pycqa/isort
29-
rev: 5.10.1
29+
rev: 5.12.0
3030
hooks:
3131
- id: isort
3232
args: [--profile=black, --lines-after-imports=2, --combine-as]
3333
- repo: https://github.com/psf/black
34-
rev: 21.12b0
34+
rev: 23.9.1
3535
hooks:
3636
- id: black
3737
- repo: https://github.com/pycqa/flake8
38-
rev: 4.0.1
38+
rev: 6.1.0
3939
hooks:
4040
- id: flake8
4141
args: ["--ignore=E203,E501,W503"]
4242
- repo: https://github.com/pre-commit/mirrors-prettier
43-
rev: v2.5.1
43+
rev: v3.0.3
4444
hooks:
4545
- id: prettier
4646
args: [--list-different, --no-semi]

app/articles/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = []

app/articles/urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from django.urls import re_path
1+
from django.urls import path, re_path
22

33
from app.articles import views
44

55

66
app_name = "articles"
77
ignore_app_name_mismatch = True # It's expected
88
urlpatterns = [
9-
re_path(
10-
r"^$",
9+
path(
10+
"",
1111
views.article_list,
1212
name="article-list",
1313
),
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
from django.shortcuts import get_object_or_404, render
1+
from django.shortcuts import render
2+
from feincms3.root.middleware import create_page_if_404_middleware
23

34
from .models import Page
45
from .renderer import renderer
56

67

7-
def page_detail(request, path=None):
8-
page = get_object_or_404(
9-
Page.objects.active(),
10-
path=f"/{path}/" if path else "/",
11-
)
8+
def handler(request, page):
129
page.activate_language(request)
1310
return render(
1411
request,
@@ -22,3 +19,8 @@ def page_detail(request, path=None):
2219
),
2320
},
2421
)
22+
23+
24+
page_if_404_middleware = create_page_if_404_middleware(
25+
queryset=lambda request: Page.objects.active(), handler=handler
26+
)

app/pages/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = []

app/pages/urls.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"django.contrib.messages.middleware.MessageMiddleware",
6262
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6363
"feincms3.applications.apps_middleware",
64+
"app.pages.middleware.page_if_404_middleware",
6465
]
6566

6667
ROOT_URLCONF = "app.urls"

app/urls.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from django.conf import settings
22
from django.conf.urls.static import static
33
from django.contrib import admin
4-
from django.urls import include, re_path
4+
from django.urls import path
55

66

7-
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT,) + [
8-
re_path(r"^admin/", admin.site.urls),
9-
re_path(r"", include("app.pages.urls")),
10-
]
7+
urlpatterns = [path("admin/", admin.site.urls)]
8+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

0 commit comments

Comments
 (0)