Skip to content

Commit

Permalink
Cache page_content in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jul 12, 2024
1 parent f31b5e0 commit d5a12ab
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict
from copy import copy
from typing import Optional

from cms.cms_toolbars import (
ADD_PAGE_LANGUAGE_BREAK,
Expand Down Expand Up @@ -288,18 +289,25 @@ class VersioningPageToolbar(PageToolbar):
Overriding the original Page toolbar to ensure that draft and published pages
can be accessed and to allow full control over the Page toolbar for versioned pages.
"""
def get_page_content(self, language=None):

def __init__(self, *args, **kwargs):
self.page_content: Optional[PageContent] = None
super().__init__(*args, **kwargs)

def get_page_content(self, language: Optional[str] = None) -> PageContent:
if not language:
language = self.current_lang

if self.page_content and self.page_content.language == language:
return self.page_content
toolbar_obj = self.toolbar.get_object()
if toolbar_obj and toolbar_obj.language == language:
return self.toolbar.get_object()
return get_latest_admin_viewable_content(self.page, language=language)

def populate(self):
self.page = self.request.current_page
self.title = self.get_page_content() if self.page else None
self.page_content = self.get_page_content() if self.page else None
self.permissions_activated = get_cms_setting("PERMISSION")

self.override_language_menu()
Expand Down

0 comments on commit d5a12ab

Please sign in to comment.