From 4f2ec2361b0fef3c7e84d553ca86819c23debd43 Mon Sep 17 00:00:00 2001 From: Paulo Date: Sat, 14 May 2016 09:52:01 -0400 Subject: [PATCH] do plugin menu calculation in placeholder --- cms/plugin_rendering.py | 7 +++++-- cms/templates/cms/toolbar/dragitem_menu.html | 6 ++---- cms/templates/cms/toolbar/placeholder.html | 3 +++ cms/templates/cms/toolbar/toolbar.html | 1 - cms/templatetags/cms_tags.py | 14 +------------- cms/toolbar/toolbar.py | 4 ++++ 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cms/plugin_rendering.py b/cms/plugin_rendering.py index 2aa06aae9fa..c5adb47ccb1 100644 --- a/cms/plugin_rendering.py +++ b/cms/plugin_rendering.py @@ -13,6 +13,7 @@ from cms.utils import get_language_from_request from cms.utils.conf import get_cms_setting, get_site_id from cms.utils.django_load import iterload_objects +from cms.utils.placeholder import get_toolbar_plugin_struct DEFAULT_PLUGIN_CONTEXT_PROCESSORS = ( @@ -229,9 +230,11 @@ def render_placeholder_toolbar(placeholder, context, name_fallback, save_languag slot = None context.push() - plugins = [cls.__name__ for cls in plugin_pool.get_all_plugins(slot, page)] + plugin_classes = plugin_pool.get_all_plugins(slot, page) + plugin_types = [cls.__name__ for cls in plugin_classes] - context['allowed_plugins'] = plugins + plugin_pool.get_system_plugins() + context['allowed_plugins'] = plugin_types + plugin_pool.get_system_plugins() + context['plugin_menu'] = get_toolbar_plugin_struct(plugin_classes, slot=slot, page=page) context['placeholder'] = placeholder context['language'] = save_language context['page'] = page diff --git a/cms/templates/cms/toolbar/dragitem_menu.html b/cms/templates/cms/toolbar/dragitem_menu.html index 66bf434b227..ae42f9557c6 100644 --- a/cms/templates/cms/toolbar/dragitem_menu.html +++ b/cms/templates/cms/toolbar/dragitem_menu.html @@ -1,12 +1,10 @@ {% load i18n %} {% language request.toolbar.toolbar_language %} -{% regroup plugin_classes by module as module_list %} +{% regroup plugin_menu by module as module_list %} {% for module in module_list %}
{% if module.grouper %}{{ module.grouper|capfirst }}{% else %}{% trans "Available plugins" %}{% endif %}
{% for p in module.list %} - {% if p.value != 'AliasPlugin' %} -
{{ p.name }}
- {% endif %} +
{{ p.name }}
{% endfor %} {% endfor %} {% endlanguage %} diff --git a/cms/templates/cms/toolbar/placeholder.html b/cms/templates/cms/toolbar/placeholder.html index f6262c29d77..3f650d7147b 100644 --- a/cms/templates/cms/toolbar/placeholder.html +++ b/cms/templates/cms/toolbar/placeholder.html @@ -20,5 +20,8 @@ } }]); + {% endlanguage %} {% endaddtoblock %} diff --git a/cms/templates/cms/toolbar/toolbar.html b/cms/templates/cms/toolbar/toolbar.html index dbb2299467a..180465a1338 100644 --- a/cms/templates/cms/toolbar/toolbar.html +++ b/cms/templates/cms/toolbar/toolbar.html @@ -118,5 +118,4 @@

{% trans "This page has no preview!" %}

{% endif %} - {% endlanguage %} diff --git a/cms/templatetags/cms_tags.py b/cms/templatetags/cms_tags.py index 13791f9d0ea..57bad7a231d 100644 --- a/cms/templatetags/cms_tags.py +++ b/cms/templatetags/cms_tags.py @@ -47,7 +47,7 @@ from cms.utils.i18n import force_language from cms.utils.moderator import use_draft from cms.utils.page_resolver import get_page_queryset -from cms.utils.placeholder import validate_placeholder_name, get_toolbar_plugin_struct, restore_sekizai_context +from cms.utils.placeholder import validate_placeholder_name, restore_sekizai_context from cms.utils.urlutils import admin_reverse DJANGO_VERSION = django.get_version() @@ -385,18 +385,6 @@ def get_context(self, context, plugin, nodelist): register.tag(RenderPluginBlock) -@register.inclusion_tag('cms/toolbar/dragitem_menu.html', takes_context=True) -def render_dragitem_menu(context): - plugins = plugin_pool.get_all_plugins() - - if plugins: - # Builds the list of dictionaries containing module, name and value for the plugin dropdowns - child_plugin_classes = get_toolbar_plugin_struct(plugins) - else: - child_plugin_classes = [] - return {'plugin_classes': child_plugin_classes} - - @register.simple_tag(takes_context=True) def render_extra_menu_items(context, obj, template='cms/toolbar/dragitem_extra_menu.html'): request = context['request'] diff --git a/cms/toolbar/toolbar.py b/cms/toolbar/toolbar.py index 4aebc5ba01c..7b1f59f749a 100644 --- a/cms/toolbar/toolbar.py +++ b/cms/toolbar/toolbar.py @@ -361,6 +361,10 @@ def get_cached_template(self, template): def drag_item_template(self): return self.get_cached_template('cms/toolbar/dragitem.html') + @cached_property + def drag_item_menu_template(self): + return self.get_cached_template('cms/toolbar/dragitem_menu.html') + @cached_property def dragbar_template(self): return self.get_cached_template('cms/toolbar/dragbar.html')