Exemplo n.º 1
0
def render_replace_response(request,
                            new_plugins,
                            source_placeholder=None,
                            source_plugin=None):
    move_plugins, add_plugins = [], []
    for plugin in new_plugins:
        root = plugin.parent.get_bound_plugin() if plugin.parent else plugin

        plugins = [root] + list(root.get_descendants())

        plugin_order = plugin.placeholder.get_plugin_tree_order(
            plugin.language,
            parent_id=plugin.parent_id,
        )
        plugin_tree = get_plugin_tree_as_json(request, plugins)
        move_data = get_plugin_toolbar_info(plugin)
        move_data['plugin_order'] = plugin_order
        move_data.update(json.loads(plugin_tree))
        move_plugins.append(json.dumps(move_data))
        add_plugins.append((
            json.dumps(get_plugin_toolbar_info(plugin)),
            plugin_tree,
        ))
    context = {
        'added_plugins': add_plugins,
        'moved_plugins': move_plugins,
        'is_popup': True,
    }
    if source_plugin is not None:
        context['replaced_plugin'] = json.dumps(
            get_plugin_toolbar_info(source_plugin), )
    if source_placeholder is not None:
        context['replaced_placeholder'] = json.dumps({
            'placeholder_id':
            source_placeholder.pk,
            'deleted':
            True,
        })
    return render(request, 'djangocms_alias/alias_replace.html', context)
Exemplo n.º 2
0
    def render_close_frame(self, request, obj, extra_context=None):
        try:
            root = obj.parent.get_bound_plugin() if obj.parent else obj
        except ObjectDoesNotExist:
            # This is a nasty edge-case.
            # If the parent plugin is a ghost plugin, fetching the plugin tree
            # will fail because the downcasting function filters out all ghost plugins.
            # Currently this case is only present in the djangocms-text-ckeditor app
            # which uses ghost plugins to create inline plugins on the text.
            root = obj

        plugins = [root] + list(root.get_descendants().order_by('path'))
        # simulate the call to the unauthorized CMSPlugin.page property
        cms_page = obj.placeholder.page if obj.placeholder_id else None

        child_classes = self.get_child_classes(
            slot=obj.placeholder.slot,
            page=cms_page,
            instance=obj,
        )

        parent_classes = self.get_parent_classes(
            slot=obj.placeholder.slot,
            page=cms_page,
            instance=obj,
        )

        data = get_plugin_toolbar_info(
            obj,
            children=child_classes,
            parents=parent_classes,
        )
        data['plugin_desc'] = escapejs(force_str(obj.get_short_description()))

        context = {
            'plugin': obj,
            'is_popup': True,
            'plugin_data': json.dumps(data),
            'plugin_structure': get_plugin_tree_as_json(request, plugins),
        }

        if extra_context:
            context.update(extra_context)
        return render_to_response(request,
                                  'admin/cms/page/plugin/confirm_form.html',
                                  context)