Skip to content

Commit 71f6b4c

Browse files
committed
Change the passthru implementation to use a subclass instead of an attribute
1 parent d10a77f commit 71f6b4c

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

feincms3/root/middleware.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ def handler(request, page):
4040

4141
from functools import wraps
4242

43-
from django.http import HttpResponseRedirect
44-
from django.urls import is_valid_path
43+
from django.http import HttpResponseNotFound, HttpResponseRedirect
44+
45+
46+
class _UseRootMiddlewareResponse(HttpResponseNotFound):
47+
"""Used by feincms3.root.passthru to tell the middleware to do its thing"""
48+
49+
pass
4550

4651

4752
def create_page_if_404_middleware(*, queryset, handler, language_code_redirect=False):
@@ -72,8 +77,8 @@ def outer(get_response):
7277
def inner(request):
7378
response = get_response(request)
7479
if response.status_code != 404 or (
75-
not getattr(response, "_root_middleware", False)
76-
and is_valid_path(request.path_info)
80+
request.resolver_match
81+
and not isinstance(response, _UseRootMiddlewareResponse)
7782
):
7883
# Response is not a 404 OR the path can be resolved and running
7984
# the middleware hasn't been requested explicitly.

feincms3/root/passthru.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,14 @@
3535
reverse_passthru("imprint", urlconf=apps_urlconf())
3636
"""
3737

38-
from django.http import HttpResponseNotFound
3938
from django.urls import path
4039

4140
from feincms3.applications import reverse_app
42-
43-
44-
def passthru(request):
45-
response = HttpResponseNotFound()
46-
# Trigger the root middleware
47-
response._root_middleware = True
48-
return response
41+
from feincms3.root.middleware import _UseRootMiddlewareResponse
4942

5043

5144
app_name = "passthru"
52-
urlpatterns = [path("", passthru, name="passthru")]
45+
urlpatterns = [path("", lambda request: _UseRootMiddlewareResponse(), name="passthru")]
5346
ignore_app_name_mismatch = True
5447

5548

0 commit comments

Comments
 (0)