Skip to content

Commit

Permalink
Fix: Remove workaround for page-specific rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed May 17, 2024
1 parent adce880 commit 23c5e6f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions djangocms_versioning/plugin_rendering.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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":

Check failure on line 45 in djangocms_versioning/plugin_rendering.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PLR1714)

djangocms_versioning/plugin_rendering.py:45:8: PLR1714 Consider merging multiple comparisons: `cms_version in ("4.1.0", "4.1.1")`. Use a `set` if the elements are hashable.

Check failure on line 45 in djangocms_versioning/plugin_rendering.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PLR1714)

djangocms_versioning/plugin_rendering.py:45:8: PLR1714 Consider merging multiple comparisons: `cms_version in ("4.1.0", "4.1.1")`. Use a `set` if the elements are hashable.
# 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):
Expand Down

0 comments on commit 23c5e6f

Please sign in to comment.