示例#1
0
def render_placeholder_toolbar_js(placeholder, render_language, content_renderer):
    page = placeholder.page
    slot = placeholder.slot
    placeholder_cache = content_renderer.get_rendered_plugins_cache(placeholder)
    rendered_plugins = placeholder_cache["plugins"]
    plugin_parents = placeholder_cache["plugin_parents"]
    plugin_children = placeholder_cache["plugin_children"]
    plugin_pool = content_renderer.plugin_pool
    plugin_types = [cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)]
    allowed_plugins = plugin_types + plugin_pool.get_system_plugins()

    get_toolbar_js = functools.partial(get_plugin_toolbar_js, request_language=content_renderer.request_language)

    def _render_plugin_js(plugin):
        content = get_toolbar_js(
            plugin, children=plugin_children[plugin.plugin_type], parents=plugin_parents[plugin.plugin_type]
        )
        return content

    plugin_js_output = "".join(_render_plugin_js(plugin) for plugin in rendered_plugins)
    placeholder_js_output = get_placeholder_toolbar_js(
        placeholder=placeholder,
        request_language=content_renderer.request_language,
        render_language=render_language,
        allowed_plugins=allowed_plugins,
    )
    return mark_safe(plugin_js_output + "\n" + placeholder_js_output)
示例#2
0
    def get_placeholder_toolbar_js(self, placeholder, page=None):
        plugins = self.plugin_pool.get_all_plugins(placeholder.slot, page) # original

        plugin_types = [cls.__name__ for cls in plugins]
        allowed_plugins = plugin_types + self.plugin_pool.get_system_plugins()
        placeholder_toolbar_js = get_placeholder_toolbar_js(
            placeholder=placeholder,
            allowed_plugins=allowed_plugins,
        )
        return placeholder_toolbar_js
示例#3
0
def render_placeholder_toolbar_js(placeholder, render_language,
                                  content_renderer):
    page = placeholder.page
    slot = placeholder.slot
    placeholder_cache = content_renderer.get_rendered_plugins_cache(
        placeholder)
    rendered_plugins = placeholder_cache['plugins']
    plugin_parents = placeholder_cache['plugin_parents']
    plugin_children = placeholder_cache['plugin_children']
    plugin_pool = content_renderer.plugin_pool
    plugin_types = [
        cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)
    ]
    allowed_plugins = plugin_types + plugin_pool.get_system_plugins()

    get_toolbar_js = functools.partial(
        get_plugin_toolbar_js,
        request_language=content_renderer.request_language,
    )

    def _render_plugin_js(plugin):
        try:
            child_classes = plugin_children[plugin.plugin_type]
        except KeyError:
            plugin_class = plugin_pool.plugins[plugin.plugin_type]
            child_classes = plugin_class.get_child_classes(slot=slot,
                                                           page=page,
                                                           instance=plugin)

        try:
            parent_classes = plugin_parents[plugin.plugin_type]
        except KeyError:
            plugin_class = plugin_pool.plugins[plugin.plugin_type]
            parent_classes = plugin_class.get_parent_classes(slot=slot,
                                                             page=page,
                                                             instance=plugin)

        content = get_toolbar_js(
            plugin,
            children=child_classes,
            parents=parent_classes,
        )
        return content

    plugin_js_output = ''.join(
        _render_plugin_js(plugin) for plugin in rendered_plugins)
    placeholder_js_output = get_placeholder_toolbar_js(
        placeholder=placeholder,
        request_language=content_renderer.request_language,
        render_language=render_language,
        allowed_plugins=allowed_plugins,
    )
    return mark_safe(plugin_js_output + '\n' + placeholder_js_output)
示例#4
0
        def render_placeholder_toolbar_js(placeholder, render_language, content_renderer):
            page = placeholder.page
            slot = placeholder.slot
            placeholder_cache = content_renderer.get_rendered_plugins_cache(placeholder)
            rendered_plugins = placeholder_cache['plugins']
            plugin_parents = placeholder_cache['plugin_parents']
            plugin_children = placeholder_cache['plugin_children']
            plugin_pool = content_renderer.plugin_pool
            plugin_types = [cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)]
            allowed_plugins = plugin_types + plugin_pool.get_system_plugins()

            get_toolbar_js = functools.partial(
                get_plugin_toolbar_js,
                request_language=content_renderer.request_language,
            )

            def _render_plugin_js(plugin):
                try:
                    child_classes = plugin_children[plugin.plugin_type]
                except KeyError:
                    child_classes = plugin.get_plugin_class().get_child_classes(slot=slot,
                                                                                page=page,
                                                                                instance=plugin)

                try:
                    parent_classes = plugin_parents[plugin.plugin_type]
                except KeyError:
                    parent_classes = plugin.get_plugin_class().get_parent_classes(slot=slot,
                                                                                  page=page,
                                                                                  instance=plugin)

                content = get_toolbar_js(
                    plugin,
                    children=child_classes,
                    parents=parent_classes,
                )
                return content

            plugin_js_output = ''.join(_render_plugin_js(plugin) for plugin in rendered_plugins)
            placeholder_js_output = get_placeholder_toolbar_js(
                placeholder=placeholder,
                request_language=content_renderer.request_language,
                render_language=render_language,
                allowed_plugins=allowed_plugins,
            )
            return mark_safe(plugin_js_output + '\n' + placeholder_js_output)