Skip to content

Commit

Permalink
Merge pull request #974 from ae-utbm/fix-page
Browse files Browse the repository at this point in the history
fix 500 error when accessing history of non-existing page
  • Loading branch information
imperosol authored Dec 29, 2024
2 parents 2f9e5bf + d200c1e commit cce7ecb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/views/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ def get_context_data(self, **kwargs):
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):
Expand Down

0 comments on commit cce7ecb

Please sign in to comment.