From d200c1e381410912736a1a8fd4c3d5494547cd76 Mon Sep 17 00:00:00 2001 From: imperosol Date: Sat, 28 Dec 2024 13:25:42 +0100 Subject: [PATCH] fix 500 error when accessing history of non-existing page --- core/views/page.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/views/page.py b/core/views/page.py index e33e84ba..51a0e1a5 100644 --- a/core/views/page.py +++ b/core/views/page.py @@ -64,16 +64,20 @@ class PageView(CanViewMixin, DetailView): class PageHistView(CanViewMixin, DetailView): model = Page template_name = "core/page_hist.jinja" + slug_field = "_full_name" + slug_url_kwarg = "page_name" + _cached_object: Page | None = None def dispatch(self, request, *args, **kwargs): - res = super().dispatch(request, *args, **kwargs) - if self.object.need_club_redirection: - return redirect("club:club_hist", club_id=self.object.club.id) - return res + page = self.get_object() + if page.need_club_redirection: + return redirect("club:club_hist", club_id=page.club.id) + return super().dispatch(request, *args, **kwargs) - def get_object(self): - self.page = Page.get_page_by_full_name(self.kwargs["page_name"]) - return self.page + def get_object(self, *args, **kwargs): + if not self._cached_object: + self._cached_object = super().get_object() + return self._cached_object class PageRevView(CanViewMixin, DetailView):