Ejemplo n.º 1
0
def render_placeholder_toolbar(placeholder, context, name_fallback,
                               save_language):
    from cms.plugin_pool import plugin_pool
    request = context['request']
    page = placeholder.page if placeholder else None
    if not page:
        page = getattr(request, 'current_page', None)
    if page:
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    context.push()

    # to restrict child-only plugins from draggables..
    context['allowed_plugins'] = [
        cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)
    ] + plugin_pool.get_system_plugins()
    context['placeholder'] = placeholder
    context['language'] = save_language
    context['page'] = page
    toolbar = render_to_string("cms/toolbar/placeholder.html", context)
    context.pop()
    return toolbar
Ejemplo n.º 2
0
def render_placeholder_toolbar(placeholder, context, name_fallback, save_language):
    from cms.plugin_pool import plugin_pool

    request = context["request"]
    page = placeholder.page if placeholder else None
    if not page:
        page = getattr(request, "current_page", None)
    if page:
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    context.push()

    # to restrict child-only plugins from draggables..
    context["allowed_plugins"] = [
        cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)
    ] + plugin_pool.get_system_plugins()
    context["placeholder"] = placeholder
    context["language"] = save_language
    context["page"] = page
    toolbar = render_to_string("cms/toolbar/placeholder.html", flatten_context(context))
    context.pop()
    return toolbar
Ejemplo n.º 3
0
def render_placeholder_toolbar(placeholder, context, name_fallback, save_language):
    from cms.plugin_pool import plugin_pool
    request = context['request']
    page = placeholder.page if placeholder else None
    if not page:
        page = getattr(request, 'current_page', None)
    if page:
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    context.push()

    all_plugins = plugin_pool.get_all_plugins()
    plugin_types = [cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)]

    context['allowed_plugins'] = plugin_types + plugin_pool.get_system_plugins()
    context['plugin_menu'] = get_toolbar_plugin_struct(all_plugins, slot=slot, page=page)
    context['placeholder'] = placeholder
    context['language'] = save_language
    context['page'] = page
    toolbar = render_to_string("cms/toolbar/placeholder.html", flatten_context(context))
    context.pop()
    return toolbar
Ejemplo n.º 4
0
def render_placeholder_toolbar(placeholder, context, name_fallback,
                               save_language):
    from cms.plugin_pool import plugin_pool
    request = context['request']
    page = placeholder.page if placeholder else None
    if not page:
        page = getattr(request, 'current_page', None)
    if page:
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    context.push()

    all_plugins = plugin_pool.get_all_plugins()
    plugin_types = [
        cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)
    ]

    context['allowed_plugins'] = plugin_types + plugin_pool.get_system_plugins(
    )
    context['plugin_menu'] = get_toolbar_plugin_struct(all_plugins,
                                                       slot=slot,
                                                       page=page)
    context['placeholder'] = placeholder
    context['language'] = save_language
    context['page'] = page
    toolbar = render_to_string("cms/toolbar/placeholder.html",
                               flatten_context(context))
    context.pop()
    return toolbar
Ejemplo n.º 5
0
def get_frontend_data_dict_for_placeholders(placeholders, request, editable=False):
    """
    Takes a list of placeholder instances and returns the data that is used by the frontend to render all contents.
    The returned dict is grouped by placeholder slots.
    """
    data_dict = {}
    for placeholder in placeholders:
        if placeholder:
            plugins = []

            # We don't use the helper method `placeholder.get_plugins()` because of the wrong order by path.
            placeholder_plugins = placeholder.cmsplugin_set.filter(language=request.LANGUAGE_CODE).order_by(
                settings.DJANGOCMS_SPA_PLUGIN_ORDER_FIELD)

            for plugin in placeholder_plugins:
                # We need the complete cascading structure of the plugins in the frontend. This is why we ignore the
                # children here and add them later in the loop.
                if not plugin.parent:
                    plugins.append(get_frontend_data_dict_for_plugin(
                        request=request,
                        plugin=plugin,
                        editable=editable)
                    )

            if plugins or editable:
                data_dict[placeholder.slot] = {
                    'type': 'cmp-%s' % placeholder.slot,
                    'plugins': plugins,
                }

            if editable:
                # This is the structure of the template `cms/toolbar/placeholder.html` that is used to register
                # the frontend editing.
                from cms.plugin_pool import plugin_pool
                plugin_types = [cls.__name__ for cls in plugin_pool.get_all_plugins(placeholder.slot, placeholder.page)]
                allowed_plugins = plugin_types + plugin_pool.get_system_plugins()

                data_dict[placeholder.slot]['cms'] = [
                    'cms-placeholder-{}'.format(placeholder.pk),
                    {
                        'type': 'placeholder',
                        'name': str(placeholder.get_label()),
                        'page_language': request.LANGUAGE_CODE,
                        'placeholder_id': placeholder.pk,
                        'plugin_language': request.LANGUAGE_CODE,
                        'plugin_restriction': [module for module in allowed_plugins],
                        'addPluginHelpTitle': 'Add plugin to placeholder {}'.format(placeholder.get_label()),
                        'urls': {
                            'add_plugin': placeholder.get_add_url(),
                            'copy_plugin': placeholder.get_copy_url()
                        }
                    }
                ]

    return data_dict