Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WIP / POC: feat: Sticky / Static placeholder functionality configurable by a 3rd party such as djangocms-alias #7575

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Draft
Show file tree
Hide file tree
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
44 changes: 12 additions & 32 deletions 44 cms/plugin_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,34 +416,6 @@ def render_page_placeholder(self, slot, context, inherit,
return content + nodelist.render(context)
return content

def render_static_placeholder(self, static_placeholder, context, nodelist=None):
user = self.request.user

if self.toolbar.edit_mode_active and user.has_perm('cms.edit_static_placeholder'):
placeholder = static_placeholder.draft
editable = True
use_cache = False
else:
placeholder = static_placeholder.public
editable = False
use_cache = True

# I really don't like these impromptu flags...
placeholder.is_static = True

content = self.render_placeholder(
placeholder,
context=context,
editable=editable,
use_cache=use_cache,
nodelist=nodelist,
)

if static_placeholder.pk not in self._rendered_static_placeholders:
# First time this static placeholder is rendered
self._rendered_static_placeholders[static_placeholder.pk] = static_placeholder
return content

def render_plugin(self, instance, context, placeholder=None, editable=False):
if not placeholder:
placeholder = instance.placeholder
Expand Down Expand Up @@ -677,13 +649,20 @@ def render_page_placeholder(self, page, placeholder, language=None):
def render_static_placeholder(self, static_placeholder, language=None):
user = self.request.user

if not user.has_perm('cms.edit_static_placeholder'):
return ''
# FIXME: Needs to be configured per Static Placeholder enabled package i.e. Alias
# Static Alias would use this
# The mechanism for how the Page would detect which Alias are attached to it,
# It's kind of template driven so this needs to be worked out still!
# if not user.has_perm('cms.edit_static_placeholder'):
# return ''

language = language or self.request_language

placeholder = static_placeholder.draft
# I really don't like these impromptu flags...
placeholder = static_placeholder

# It's this flag that shows the content
# TODO: This should / could be set by Alias
# for statis Alias
placeholder.is_static = True

content = self.render_placeholder(placeholder, language=language)
Expand All @@ -708,6 +687,7 @@ def render_plugins(self, placeholder, language, page=None):


class LegacyRenderer(ContentRenderer):
# FIXME: Remove this as it's uses were not known 5+ years ago, they are still not now!

load_structure = True
placeholder_edit_template = (
Expand Down
33 changes: 33 additions & 0 deletions 33 cms/templatetags/cms_js_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ def render_cms_structure_js(renderer, obj):
placeholder_js = renderer.render_placeholder(obj_placeholder, language=None, page=obj)
markup_bits.append(placeholder_js)


# https://github.com/django-cms/django-cms/commit/0f12156c8ed85914d4e3b14b30bce87becefe92b
static_placeholders = []
# declared_static_placeholders = cms_page.get_declared_static_placeholders(context)

# djangocms-alias is hacked in here, needs a configuration mechanism tuned in
# Potentially a configure Page Sticky placeholders
# By default it's empty.
# A 3rd party package will add the config.
# Needs to be like: get_declared_placeholders_for_obj
#
# Also needs to be decided if the Alias can be edited inline or if the link takes the user off to edit the alias.


from djangocms_alias.models import Alias

# HACK to test by code
Alias.objects.all().update(static_code="static")

alias_set = Alias.objects.filter(static_code="static")

for alias in alias_set:

alias_placeholder = alias.get_placeholder(language="en", show_draft_content=True)
# if obj_placeholder:
# placeholder_js = renderer.render_placeholder(obj_placeholder, language=None, page=obj)
# markup_bits.append(placeholder_js)
static_placeholders.append(alias_placeholder)

for placeholder in static_placeholders:
placeholder_js = renderer.render_static_placeholder(placeholder)
markup_bits.append(placeholder_js)

return mark_safe('\n'.join(markup_bits))


Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.