Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Segmentation rendering and toolbar working*
Browse files Browse the repository at this point in the history
* still weirdness that the plugin needs to be rendered in new style
  rendering (with separate structure rendering)
  • Loading branch information
stefanfoulis committed Aug 23, 2017
1 parent de0385f commit 79e099d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 96 deletions.
2 changes: 0 additions & 2 deletions aldryn_segmentation/cms_plugins/segment_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def render(self, context, instance, placeholder):
context, instance)
return context


def is_context_appropriate(self, context, instance):
'''
Returns True if any of its children are context-appropriate,
Expand All @@ -41,7 +40,6 @@ def is_context_appropriate(self, context, instance):
num_apt = sum( 1 for child in apt_children if child[1] )
return num_apt > 0


def get_context_appropriate_children(self, context, instance):
from ..segment_pool import SegmentOverride
'''
Expand Down
File renamed without changes.
104 changes: 10 additions & 94 deletions aldryn_segmentation/templatetags/segmentation_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,21 @@
from cms.toolbar.utils import get_toolbar_from_request
from django import template

from classytags.core import Options
from classytags.arguments import Argument

from cms.templatetags.cms_tags import render_plugin

from ..segment_pool import SegmentOverride
from cms.templatetags import cms_tags


register = template.Library()


def plugin_is_renderable(context, plugin_instance):
'''
Determines whether this plugin is to be rendered in this context.
'''
child_plugin = plugin_instance.get_plugin_class_instance()

try:
# This is for the toolbar to be able to override the "active" state
# to test as a content editor.
allow_overrides = child_plugin.allow_overrides
get_override = child_plugin.get_segment_override
except AttributeError:
# This doesn't quack like a SegmentPlugin, so, it always renders.
return True

# This is a segment plugin... or at least quacks like one.
if allow_overrides:
# only evaluate override if we allow overrides
override = get_override(context, plugin_instance)

if override == SegmentOverride.ForcedActive:
return True
elif override == SegmentOverride.ForcedInactive:
return False

# OK, what does the plugin's is_context_appropriate() say?
return child_plugin.is_context_appropriate(context, plugin_instance)


@register.simple_tag(takes_context=True)
def render_segment_plugin(context, plugin, render_plugin):
request = context['request']
toolbar = get_toolbar_from_request(request)
is_renderable = plugin_is_renderable(context, plugin)
if toolbar.uses_legacy_structure_mode:
# We need to handle it the old way. Render ALL plugins on the page so
# that the legacy structure board can display all of them.
rendered = render_plugin(context, plugin)
if render_plugin and is_renderable:
rendered = cms_tags.render_plugin(context, plugin)
if render_plugin:
return rendered
else:
# We had to render the plugin and all its sub-plugins above and
Expand All @@ -68,59 +33,10 @@ def render_segment_plugin(context, plugin, render_plugin):
# The structure including all the hidden plugins is handled
# entirely separate. So we don't have to worry about it here.
# We only need to render plugins that are actually visible.
if is_renderable:
return render_plugin(context, plugin)


# class RenderSegmentPlugin(RenderPlugin):
# name = 'render_segment_plugin'
# options = Options(
# Argument('plugin'),
# Argument('render_plugin')
# )
#
# def is_renderable(self, context, plugin_instance):
# '''
# Determines whether this plugin is to be rendered in this context.
# '''
#
# # TODO: Seems to me this method is not necessary
# # Once tests are established then maybe we can remove this.
#
# child_plugin = plugin_instance.get_plugin_class_instance()
#
# try:
# # This is for the toolbar to be able to override the "active" state
# # to test as a content editor.
# allow_overrides = child_plugin.allow_overrides
# get_override = child_plugin.get_segment_override
# except AttributeError:
# # This doesn't quack like a SegmentPlugin, so, it always renders.
# return True
#
# # This is a segment plugin... or at least quacks like one.
# if allow_overrides:
# # only evaluate override if we allow overrides
# override = get_override(context, plugin_instance)
#
# if override == SegmentOverride.ForcedActive:
# return True
# elif override == SegmentOverride.ForcedInactive:
# return False
#
# # OK, what does the plugin's is_context_appropriate() say?
# return child_plugin.is_context_appropriate(context, plugin_instance)
#
# def render_tag(self, context, plugin, render_plugin):
# response = super(RenderSegmentPlugin, self).render_tag(context, plugin)
#
# if not (render_plugin and self.is_renderable(context, plugin)):
# # OK, this is a Segmentation Plugin that is NOT appropriate for
# # rendering in the current context. Unfortunately, we need to
# # render the plugin, but throw away the results in order to allow
# # the structureboard to display properly. Ugh!
# return ''
# return response


# register.tag(RenderSegmentPlugin)
if render_plugin:
return cms_tags.render_plugin(context, plugin)
else:
# FIXME: hmmm... why does the popup not work if the plugin is not
# rendered? It should work without it.
cms_tags.render_plugin(context, plugin)
return ''

0 comments on commit 79e099d

Please sign in to comment.