Exemple #1
0
 def get_context(self, context, obj):
     # Prepend frontedit toolbar output if applicable
     request = context['request']
     page = request.current_page
     child_plugin_classes = []
     if isinstance(obj, CMSPlugin):
         slot = context['slot']
         plugin = obj
         plugin_class = plugin.get_plugin_class()
         if plugin_class.allow_children:
             instance, plugin = plugin.get_plugin_instance()
             plugin.cms_plugin_instance = instance
             childs = [plugin_pool.get_plugin(cls) for cls in plugin.get_child_classes(slot, page)]
             # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
             child_plugin_classes = get_toolbar_plugin_struct(childs, slot, page, parent=plugin_class)
     elif isinstance(obj, PlaceholderModel):
         placeholder = obj
         page = placeholder.page if placeholder else None
         if not page:
             page = getattr(request, 'current_page', None)
         if placeholder:
             slot = placeholder.slot
         else:
             slot = None
         # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
         child_plugin_classes = get_toolbar_plugin_struct(plugin_pool.get_all_plugins(slot, page), slot, page)
     return {'plugin_classes': child_plugin_classes}
Exemple #2
0
 def get_context(self, context, obj):
     # Prepend frontedit toolbar output if applicable
     request = context['request']
     page = request.current_page
     child_plugin_classes = []
     if isinstance(obj, CMSPlugin):
         slot = context['slot']
         plugin = obj
         plugin_class = plugin.get_plugin_class()
         if plugin_class.allow_children:
             instance, plugin = plugin.get_plugin_instance()
             childs = [
                 plugin_pool.get_plugin(cls)
                 for cls in plugin.get_child_classes(slot, page)
             ]
             # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
             child_plugin_classes = get_toolbar_plugin_struct(
                 childs, slot, page, parent=plugin_class)
     elif isinstance(obj, PlaceholderModel):
         placeholder = obj
         page = placeholder.page if placeholder else None
         if not page:
             page = getattr(request, 'current_page', None)
         if placeholder:
             slot = placeholder.slot
         else:
             slot = None
         # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
         child_plugin_classes = get_toolbar_plugin_struct(
             plugin_pool.get_all_plugins(slot, page), slot, page)
     return {'plugin_classes': child_plugin_classes}
Exemple #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
Exemple #4
0
def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
    from cms.plugin_pool import plugin_pool

    original_context.push()
    child_plugin_classes = []
    plugin_class = instance.get_plugin_class()
    if plugin_class.allow_children:
        inst, plugin = instance.get_plugin_instance()
        page = original_context['request'].current_page
        children = [plugin_pool.get_plugin(cls) for cls in plugin.get_child_classes(placeholder, page)]
        # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
        child_plugin_classes = get_toolbar_plugin_struct(children, placeholder.slot, placeholder.page,
                                                         parent=plugin_class)
    instance.placeholder = placeholder
    request = original_context['request']
    with force_language(request.toolbar.toolbar_language):
        data = {
            'instance': instance,
            'rendered_content': rendered_content,
            'child_plugin_classes': child_plugin_classes,
            'edit_url': placeholder.get_edit_url(instance.pk),
            'add_url': placeholder.get_add_url(),
            'delete_url': placeholder.get_delete_url(instance.pk),
            'move_url': placeholder.get_move_url(),
        }
    original_context.update(data)
    output = render_to_string(instance.get_plugin_class().frontend_edit_template, original_context)
    original_context.pop()
    return output
Exemple #5
0
def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
    from cms.plugin_pool import plugin_pool

    original_context.push()
    child_plugin_classes = []
    plugin_class = instance.get_plugin_class()
    if plugin_class.allow_children:
        inst, plugin = instance.get_plugin_instance()
        page = original_context['request'].current_page
        plugin.cms_plugin_instance = inst
        children = [plugin_pool.get_plugin(cls) for cls in plugin.get_child_classes(placeholder, page)]
        # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
        child_plugin_classes = get_toolbar_plugin_struct(children, placeholder.slot, placeholder.page,
                                                         parent=plugin_class)
    instance.placeholder = placeholder
    request = original_context['request']
    with force_language(request.toolbar.toolbar_language):
        data = {
            'instance': instance,
            'rendered_content': rendered_content,
            'child_plugin_classes': child_plugin_classes,
        }
        # TODO: Remove js_compat once get_action_urls is refactored.
        data.update(instance.get_action_urls(js_compat=False))
    original_context.update(data)
    plugin_class = instance.get_plugin_class()
    template = plugin_class.frontend_edit_template
    output = render_to_string(template, flatten_context(original_context)).strip()
    original_context.pop()
    return output
def render_placeholder_toolbar(placeholder, context, content, name_fallback=None):
    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:
        template = page.template
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    else:
        template = None
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
    installed_plugins = get_toolbar_plugin_struct(plugin_pool.get_all_plugins(slot, page), slot, page)

    name = get_placeholder_conf("name", slot, template, title(slot))
    name = _(name)
    context.push()
    context["installed_plugins"] = installed_plugins
    ## to restrict child-only plugins from draggables..
    context["allowed_plugins"] = [cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)]
    context["language"] = get_language_from_request(request)
    context["placeholder_label"] = name
    context["placeholder"] = placeholder
    context["page"] = page
    toolbar = render_to_string("cms/toolbar/placeholder_bar.html", context)
    context.pop()
    return toolbar
Exemple #7
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
Exemple #8
0
 def get_placeholder_plugin_menu(self, placeholder, page=None):
     registered_plugins = self.plugin_pool.registered_plugins
     can_add_plugin = partial(has_plugin_permission, user=self.request.user, permission_type='add')
     plugins = [plugin for plugin in registered_plugins if can_add_plugin(plugin_type=plugin.value)]
     plugin_menu = get_toolbar_plugin_struct(
         plugins=plugins,
         slot=placeholder.slot,
         page=page,
     )
     plugin_menu_template = self.templates.placeholder_plugin_menu_template
     return plugin_menu_template.render({'plugin_menu': plugin_menu})
Exemple #9
0
 def get_form(self, request, obj=None, **kwargs):
     plugins = get_toolbar_plugin_struct(
         plugin_pool.get_text_enabled_plugins(self.placeholder.slot, self.page),
         self.placeholder.slot,
         self.page,
         parent=self.__class__,
     )
     pk = self.cms_plugin_instance.pk
     form = self.get_form_class(
         request, plugins, pk, self.cms_plugin_instance.placeholder, self.cms_plugin_instance.language
     )
     kwargs["form"] = form  # override standard form
     return super(TextPlugin, self).get_form(request, obj, **kwargs)
Exemple #10
0
 def get_form(self, request, obj=None, **kwargs):
     plugins = get_toolbar_plugin_struct(
         plugin_pool.get_text_enabled_plugins(self.placeholder.slot,
                                              self.page),
         self.placeholder.slot,
         self.page,
         parent=self.__class__)
     pk = self.cms_plugin_instance.pk
     form = self.get_form_class(request, plugins, pk,
                                self.cms_plugin_instance.placeholder,
                                self.cms_plugin_instance.language)
     kwargs['form'] = form  # override standard form
     return super(TextPlugin, self).get_form(request, obj, **kwargs)
Exemple #11
0
 def get_context(self, context, plugin):
     # Prepend frontedit toolbar output if applicable
     request = context['request']
     page = request.current_page
     slot = context['slot']
     child_plugin_classes = []
     plugin_class = plugin.get_plugin_class()
     if plugin_class.allow_children:
         instance, plugin = plugin.get_plugin_instance()
         childs = [plugin_pool.get_plugin(cls) for cls in plugin.get_child_classes(slot, page)]
         # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
         child_plugin_classes = get_toolbar_plugin_struct(childs, slot, page, parent=plugin_class)
     return {'plugin_classes': child_plugin_classes}
Exemple #12
0
    def render_editable_placeholder(self, placeholder, context, language):
        plugin_menu = get_toolbar_plugin_struct(
            plugins=self.registered_plugins,
            slot=placeholder.slot,
            page=placeholder.page,
        )
        new_context = {
            'plugin_menu': plugin_menu,
            'placeholder': placeholder,
            'language': language,
        }

        with context.push(new_context):
            return self.placeholder_toolbar_template.render(context.flatten())
    def render_editable_placeholder(self, placeholder, context, language):
        plugin_menu = get_toolbar_plugin_struct(
            plugins=self.registered_plugins,
            slot=placeholder.slot,
            page=placeholder.page,
        )
        new_context = {
            'plugin_menu': plugin_menu,
            'placeholder': placeholder,
            'language': language,
        }

        with context.push(new_context):
            return self.placeholder_toolbar_template.render(context.flatten())
    def render_editable_placeholder(self, placeholder, context, language):
        can_add_plugin = partial(has_plugin_permission, user=self.request.user, permission_type='add')
        plugins = [plugin for plugin in self.registered_plugins if can_add_plugin(plugin_type=plugin.value)]
        plugin_menu = get_toolbar_plugin_struct(
            plugins=plugins,
            slot=placeholder.slot,
            page=placeholder.page,
        )
        new_context = {
            'plugin_menu': plugin_menu,
            'placeholder': placeholder,
            'language': language,
        }

        with context.push(new_context):
            return self.placeholder_toolbar_template.render(context.flatten())
Exemple #15
0
 def get_context(self, context, plugin):
     # Prepend frontedit toolbar output if applicable
     request = context['request']
     page = request.current_page
     slot = context['slot']
     child_plugin_classes = []
     plugin_class = plugin.get_plugin_class()
     if plugin_class.allow_children:
         instance, plugin = plugin.get_plugin_instance()
         childs = [
             plugin_pool.get_plugin(cls)
             for cls in plugin.get_child_classes(slot, page)
         ]
         # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
         child_plugin_classes = get_toolbar_plugin_struct(
             childs, slot, page, parent=plugin_class)
     return {'plugin_classes': child_plugin_classes}
Exemple #16
0
def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
    original_context.push()
    child_plugin_classes = []
    plugin_class = instance.get_plugin_class()
    if plugin_class.allow_children:
        instance, plugin = instance.get_plugin_instance()
        page = original_context['request'].current_page
        childs = [plugin_pool.get_plugin(cls) for cls in plugin.get_child_classes(placeholder, page)]
        # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
        child_plugin_classes = get_toolbar_plugin_struct(childs, placeholder.slot, placeholder.page, parent=plugin_class)
    data = {
        'instance': instance,
        'rendered_content': rendered_content,
        'child_plugin_classes': child_plugin_classes,
    }
    original_context.update(data)
    output = render_to_string(instance.get_plugin_class().frontend_edit_template, original_context)
    original_context.pop()
    return output
 def get_form(self, request, obj=None, **kwargs):
     get_plugin = plugin_pool.get_plugin
     child_plugin_types = self.get_child_classes(
         slot=self.placeholder.slot,
         page=self.page,
     )
     child_plugins = (get_plugin(name) for name in child_plugin_types)
     plugins = get_toolbar_plugin_struct(
         child_plugins,
         self.placeholder.slot,
         self.page,
     )
     form = self.get_form_class(
         request=request,
         plugins=plugins,
         plugin=self.cms_plugin_instance,
     )
     kwargs['form'] = form  # override standard form
     return super(TextPlugin, self).get_form(request, obj, **kwargs)
def render_placeholder_toolbar(placeholder,
                               context,
                               content,
                               name_fallback=None):
    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:
        template = page.template
        if name_fallback and not placeholder:
            placeholder = Placeholder.objects.create(slot=name_fallback)
            page.placeholders.add(placeholder)
            placeholder.page = page
    else:
        template = None
    if placeholder:
        slot = placeholder.slot
    else:
        slot = None
    # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
    installed_plugins = get_toolbar_plugin_struct(
        plugin_pool.get_all_plugins(slot, page), slot, page)

    name = get_placeholder_conf("name", slot, template, title(slot))
    name = _(name)
    context.push()
    context['installed_plugins'] = installed_plugins
    ## to restrict child-only plugins from draggables..
    context['allowed_plugins'] = [
        cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)
    ]
    context['language'] = get_language_from_request(request)
    context['placeholder_label'] = name
    context['placeholder'] = placeholder
    context['page'] = page
    toolbar = render_to_string("cms/toolbar/placeholder_bar.html", context)
    context.pop()
    return toolbar
    def render_editable_placeholder(self, placeholder, context, language):
        can_add_plugin = partial(has_plugin_permission,
                                 user=self.request.user,
                                 permission_type='add')
        plugins = [
            plugin for plugin in self.registered_plugins
            if can_add_plugin(plugin_type=plugin.value)
        ]
        plugin_menu = get_toolbar_plugin_struct(
            plugins=plugins,
            slot=placeholder.slot,
            page=placeholder.page,
        )
        new_context = {
            'plugin_menu': plugin_menu,
            'placeholder': placeholder,
            'language': language,
        }

        with context.push(new_context):
            return self.placeholder_toolbar_template.render(context.flatten())
Exemple #20
0
def toolbar_plugin_processor(instance, placeholder, rendered_content,
                             original_context):
    from cms.plugin_pool import plugin_pool

    original_context.push()
    child_plugin_classes = []
    plugin_class = instance.get_plugin_class()
    if plugin_class.allow_children:
        inst, plugin = instance.get_plugin_instance()
        page = original_context['request'].current_page
        plugin.cms_plugin_instance = inst
        children = [
            plugin_pool.get_plugin(cls)
            for cls in plugin.get_child_classes(placeholder, page)
        ]
        # Builds the list of dictionaries containing module, name and value for the plugin dropdowns
        child_plugin_classes = get_toolbar_plugin_struct(children,
                                                         placeholder.slot,
                                                         placeholder.page,
                                                         parent=plugin_class)
    instance.placeholder = placeholder
    request = original_context['request']
    with force_language(request.toolbar.toolbar_language):
        data = {
            'instance': instance,
            'rendered_content': rendered_content,
            'child_plugin_classes': child_plugin_classes,
        }
        # TODO: Remove js_compat once get_action_urls is refactored.
        data.update(instance.get_action_urls(js_compat=False))
    original_context.update(data)
    plugin_class = instance.get_plugin_class()
    template = plugin_class.frontend_edit_template
    output = render_to_string(template,
                              flatten_context(original_context)).strip()
    original_context.pop()
    return output