fixed: plugins not listening to events in structure mode
@@ -10,6 +10,7 @@ from django.contrib.staticfiles import finders
from django.utils.safestring import mark_safe
from classytags.arguments import Argument
from classytags.core import Options, Tag
+from cmsplugin_cascade.strides import StrideContentRenderer
register = template.Library()
@@ -32,37 +33,39 @@ class StrideRenderer(Tag):
from sekizai.helpers import get_varname as get_sekizai_context_key
from cmsplugin_cascade.strides import StrideContentRenderer
- content_renderer = StrideContentRenderer(context['request'])
- tree_data_key = 'cascade-strides:' + datafile
- sekizai_context_key = get_sekizai_context_key()
-
cache = caches['default']
+ tree_data_key = 'cascade-strides:' + datafile
tree_data = cache.get(tree_data_key) if cache else None
if tree_data is None:
jsonfile = finders.find(datafile)
if not jsonfile:
raise IOError("Unable to find file: {}".format(datafile))
+
with io.open(jsonfile) as fp:
tree_data = json.load(fp)
- if cache:
- cache.set(tree_data_key, tree_data)
+ content_renderer = StrideContentRenderer(context['request'])
with context.push(cms_content_renderer=content_renderer):
content = content_renderer.render_cascade(context, tree_data)
# some templates use Sekizai's templatetag `addtoblock` or `add_data`, which have to be re-added to the context
cache = caches['default']
if cache:
+ sekizai_context_key = get_sekizai_context_key()
SEKIZAI_CONTENT_HOLDER = cache.get_or_set(sekizai_context_key, context.get(sekizai_context_key))
if SEKIZAI_CONTENT_HOLDER:
for name in SEKIZAI_CONTENT_HOLDER:
- context[sekizai_context_key].setdefault(name, SEKIZAI_CONTENT_HOLDER[name])
+ context[sekizai_context_key][name] = SEKIZAI_CONTENT_HOLDER[name]
return content
register.tag('render_cascade', StrideRenderer)
class RenderPlugin(Tag):
+ """
+ Alternative implementation of django-CMS's templatetag ``render_plugin``.
+ It can either handle normal CMS plugins or Strides.
+ """
name = 'render_plugin'
options = Options(
Argument('plugin')
@@ -72,8 +75,16 @@ class RenderPlugin(Tag):
if not plugin:
return ''
- toolbar = get_toolbar_from_request(context['request'])
- content_renderer = context.get('cms_content_renderer', toolbar.content_renderer)
+ request = context['request']
+ toolbar = get_toolbar_from_request(request)
+ if 'cms_content_renderer' in context and isinstance(context['cms_content_renderer'], StrideContentRenderer):
+ content_renderer = context['cms_content_renderer']
+ elif 'cms_renderer' in context:
+ content_renderer = context['cms_renderer']
+ elif 'cms_content_renderer' in context:
+ content_renderer = context['cms_content_renderer']
+ else:
+ content_renderer = toolbar.content_renderer
content = content_renderer.render_plugin(
instance=plugin,
context=context,
