Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove workaround for page-specific rendering #411

Merged
merged 3 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 in ("4.1.0", "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):
Expand Down
Loading