From 23c5e6f5382b6ecea3e2c34381eec616e3a8b31a Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Fri, 17 May 2024 23:48:17 +0200 Subject: [PATCH] Fix: Remove workaround for page-specific rendering --- djangocms_versioning/plugin_rendering.py | 46 +++++++++++++----------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/djangocms_versioning/plugin_rendering.py b/djangocms_versioning/plugin_rendering.py index 7571bbaf..43ead8fa 100644 --- a/djangocms_versioning/plugin_rendering.py +++ b/djangocms_versioning/plugin_rendering.py @@ -1,5 +1,6 @@ from functools import lru_cache +from cms import __version__ as cms_version from cms.plugin_rendering import ContentRenderer, StructureRenderer from cms.utils.placeholder import rescan_placeholders_for_obj @@ -41,29 +42,32 @@ def render_plugin(self, instance, context, placeholder=None, editable=False): prefetch_versioned_related_objects(instance, self.toolbar) return super().render_plugin(instance, context, placeholder, editable) - def render_obj_placeholder( - self, slot, context, inherit, nodelist=None, editable=True - ): - # FIXME This is an ad-hoc solution for page-specific rendering - # code, which by default doesn't work well with versioning. - # Remove this method once the issue is fixed. - from cms.models import Placeholder + if cms_version == "4.1.0" or cms_version == "4.1.1": + # Only needed for CMS 4.1.0 and 4.1.1 which have fix #7952 not merged + # With #7952, page-specific rendering works well with versioning. + def render_obj_placeholder( + self, slot, context, inherit, nodelist=None, editable=True + ): + # FIXME This is an ad-hoc solution for page-specific rendering + # code, which by default doesn't work well with versioning. + # Remove this method once the issue is fixed. + from cms.models import Placeholder - current_obj = self.toolbar.get_object() + current_obj = self.toolbar.get_object() - # Not page, therefore we will use toolbar object as - # the current object and render the placeholder - rescan_placeholders_for_obj(current_obj) - placeholder = Placeholder.objects.get_for_obj(current_obj).get(slot=slot) - content = self.render_placeholder( - placeholder, - context=context, - page=current_obj, - editable=editable, - use_cache=True, - nodelist=None, - ) - return content + # Not page, therefore we will use toolbar object as + # the current object and render the placeholder + rescan_placeholders_for_obj(current_obj) + placeholder = Placeholder.objects.get_for_obj(current_obj).get(slot=slot) + content = self.render_placeholder( + placeholder, + context=context, + page=current_obj, + editable=editable, + use_cache=True, + nodelist=None, + ) + return content class VersionStructureRenderer(StructureRenderer):