Ejemplo n.º 1
0
    def get_all_allowed_plugins(self):
        """
        By default, all plugins are allowed, unless a placeholder puts a limit on this.
        The page will load much faster if the plugin types are limited globally here.
        """
        if self.all_allowed_plugins:
            # Limit the globally available plugins,
            # using the statically defined list.
            try:
                return plugin_pool.get_plugins_by_name(*self.all_allowed_plugins)
            except PluginNotFound as e:
                raise PluginNotFound(str(e) + " Update the plugin list of the {0}.all_allowed_plugins setting.".format(self.__class__.__name__))
        elif self.placeholder_layout_template:
            # This page is edited with a fixed template.
            # Extract all slot names from the template, and base the list of plugins on that.
            # Note that this actually parses the template, but it will be cached for production environments.
            template = get_template(self.placeholder_layout_template)
            slots = [placeholder.slot for placeholder in get_template_placeholder_data(template)]

            # Resolve all plugins.
            plugins = []
            for slot in slots:
                plugins.extend(plugin_pool.get_allowed_plugins(slot))
            plugins = list(set(plugins))

            # The list of names can be stored statically because it won't change anyway.
            # Otherwise it would be read at least 3 times in a request,
            # from the admin get_inline_instances(), get_formset() and
            if not settings.DEBUG:
                self.all_allowed_plugins = [plugin.name for plugin in plugins]

            return plugins
        else:
            # Accepts all plugins by default
            return super(FluentContentsPageAdmin, self).get_all_allowed_plugins()
Ejemplo n.º 2
0
    def get_all_allowed_plugins(self):
        """
        By default, all plugins are allowed, unless a placeholder puts a limit on this.
        The page will load much faster if the plugin types are limited globally here.
        """
        if self.all_allowed_plugins:
            # Limit the globally available plugins,
            # using the statically defined list.
            try:
                return plugin_pool.get_plugins_by_name(*self.all_allowed_plugins)
            except PluginNotFound as e:
                raise PluginNotFound(str(e) + " Update the plugin list of the {0}.all_allowed_plugins setting.".format(self.__class__.__name__))
        elif self.placeholder_layout_template:
            # This page is edited with a fixed template.
            # Extract all slot names from the template, and base the list of plugins on that.
            # Note that this actually parses the template, but it will be cached for production environments.
            template = get_template(self.placeholder_layout_template)
            slots = [placeholder.slot for placeholder in get_template_placeholder_data(template)]

            # Resolve all plugins.
            plugins = []
            for slot in slots:
                plugins.extend(plugin_pool.get_allowed_plugins(slot))
            plugins = list(set(plugins))

            # The list of names can be stored statically because it won't change anyway.
            # Otherwise it would be read at least 3 times in a request,
            # from the admin get_inline_instances(), get_formset() and
            if not settings.DEBUG:
                self.all_allowed_plugins = [plugin.name for plugin in plugins]

            return plugins
        else:
            # Accepts all plugins by default
            return super(FluentContentsPageAdmin, self).get_all_allowed_plugins()
Ejemplo n.º 3
0
 def get_all_allowed_plugins(self):
     """
     By default, all plugins are allowed, unless a placeholder puts a limit on this.
     The page will load much faster if the plugin types are limited globally here.
     """
     if self.all_allowed_plugins:
         # Limit the globally available plugins,
         # using the statically defined list.
         try:
             return plugin_pool.get_plugins_by_name(*self.all_allowed_plugins)
         except PluginNotFound as e:
             raise PluginNotFound(str(e) + " Update the plugin list of the {0}.all_allowed_plugins setting.".format(self.__class__.__name__))
     else:
         # Accepts all plugins by default
         return super(FluentContentsPageAdmin, self).get_all_allowed_plugins()