mirror of
https://github.com/ae-utbm/sith.git
synced 2025-01-04 22:21:19 +00:00
Merge pull request #974 from ae-utbm/fix-page
fix 500 error when accessing history of non-existing page
This commit is contained in:
commit
cce7ecbe73
@ -64,16 +64,20 @@ class PageView(CanViewMixin, DetailView):
|
|||||||
class PageHistView(CanViewMixin, DetailView):
|
class PageHistView(CanViewMixin, DetailView):
|
||||||
model = Page
|
model = Page
|
||||||
template_name = "core/page_hist.jinja"
|
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):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
res = super().dispatch(request, *args, **kwargs)
|
page = self.get_object()
|
||||||
if self.object.need_club_redirection:
|
if page.need_club_redirection:
|
||||||
return redirect("club:club_hist", club_id=self.object.club.id)
|
return redirect("club:club_hist", club_id=page.club.id)
|
||||||
return res
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self, *args, **kwargs):
|
||||||
self.page = Page.get_page_by_full_name(self.kwargs["page_name"])
|
if not self._cached_object:
|
||||||
return self.page
|
self._cached_object = super().get_object()
|
||||||
|
return self._cached_object
|
||||||
|
|
||||||
|
|
||||||
class PageRevView(CanViewMixin, DetailView):
|
class PageRevView(CanViewMixin, DetailView):
|
||||||
|
Loading…
Reference in New Issue
Block a user