Skip to content

Commit

Permalink
fix: fix APPEND_SLASH django config
Browse files Browse the repository at this point in the history
  • Loading branch information
bnznamco committed Nov 8, 2023
1 parent 7dd4edf commit 81a43e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions camomilla/dynamic_pages_urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from django.shortcuts import render
from django.shortcuts import redirect, render
from django.urls import path

from camomilla import settings

from django.conf import settings as django_settings
from .models import Page


def fetch(request, *args, **kwargs):
preview = request.user.is_staff and request.GET.get("preview", False)
append_slash = getattr(django_settings, "APPEND_SLASH", True)
if append_slash and not request.path.endswith("/"):
return redirect(request.path + "/")
if "permalink" in kwargs:
page = Page.get_or_404(
request, bypass_public_check=preview, bypass_type_check=True
Expand Down
7 changes: 5 additions & 2 deletions camomilla/models/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from camomilla.utils.getters import pointed_getter
from camomilla import settings
from camomilla.templates_context.rendering import ctx_registry
from django.conf import settings as django_settings


def GET_TEMPLATE_CHOICES():
Expand Down Expand Up @@ -314,12 +315,14 @@ def save(self, *args, **kwargs) -> None:
def get(cls, request, *args, **kwargs) -> "AbstractPage":
bypass_type_check = kwargs.pop("bypass_type_check", False)
bypass_public_check = kwargs.pop("bypass_public_check", False)

path = request.path
if getattr(django_settings, "APPEND_SLASH", True):
path = path.rstrip("/")
if len(kwargs.keys()) > 0:
page = cls.objects.get(**kwargs)
else:
node = UrlNode.objects.filter(
permalink=url_lang_decompose(request.path)["permalink"]
permalink=url_lang_decompose(path)["permalink"]
).first()
page = node and node.page
type_error = not bypass_type_check and not isinstance(page, cls)
Expand Down

0 comments on commit 81a43e2

Please sign in to comment.