Exemplo n.º 1
0
def render_plugin(context,
                  instance,
                  placeholder,
                  template,
                  processors=None,
                  current_app=None):
    """
    Renders a single plugin and applies the post processors to it's rendered
    content.
    """
    if current_app:
        context['request'].current_app = current_app
    if not processors:
        processors = []
    if isinstance(template, six.string_types):
        content = render_to_string(template, flatten_context(context))
    elif (isinstance(template, Template)
          or (hasattr(template, 'template') and hasattr(template, 'render')
              and isinstance(template.template, Template))):
        content = template.render(context)
    else:
        content = ''
    for processor in iterload_objects(get_cms_setting('PLUGIN_PROCESSORS')):
        content = processor(instance, placeholder, content, context)
    for processor in processors:
        content = processor(instance, placeholder, content, context)
    for processor in DEFAULT_PLUGIN_PROCESSORS:
        content = processor(instance, placeholder, content, context)
    return content
Exemplo n.º 2
0
def render_plugin(context, instance, placeholder, template, processors=None, current_app=None):
    """
    Renders a single plugin and applies the post processors to it's rendered
    content.
    """
    request = context.get('request')

    if request:
        toolbar = getattr(request, 'toolbar', None)

        if current_app:
            request.current_app = current_app
    else:
        toolbar = None

    if toolbar and isinstance(template, six.string_types):
        template = toolbar.get_cached_template(template)

    if not processors:
        processors = []
    if isinstance(template, six.string_types):
        content = render_to_string(template, flatten_context(context))
    elif (isinstance(template, Template) or (hasattr(template, 'template') and
          hasattr(template, 'render') and isinstance(template.template, Template))):
        content = template.render(context)
    else:
        content = ''
    for processor in iterload_objects(get_cms_setting('PLUGIN_PROCESSORS')):
        content = processor(instance, placeholder, content, context)
    for processor in processors:
        content = processor(instance, placeholder, content, context)
    for processor in DEFAULT_PLUGIN_PROCESSORS:
        content = processor(instance, placeholder, content, context)
    return content
Exemplo n.º 3
0
def render_plugin(context,
                  instance,
                  placeholder,
                  template,
                  processors=None,
                  current_app=None):
    """
    Renders a single plugin and applies the post processors to it's rendered
    content.
    """
    if not processors:
        processors = []
    if isinstance(template, string_types):
        content = render_to_string(template, context_instance=context)
    elif isinstance(template, Template):
        content = template.render(context)
    else:
        content = ''
    for processor in iterload_objects(get_cms_setting('PLUGIN_PROCESSORS')):
        content = processor(instance, placeholder, content, context)
    for processor in processors:
        content = processor(instance, placeholder, content, context)
    for processor in DEFAULT_PLUGIN_PROCESSORS:
        content = processor(instance, placeholder, content, context)
    return content
Exemplo n.º 4
0
 def __init__(self, dict, instance, placeholder, processors=None, current_app=None):
     super(PluginContext, self).__init__(dict, current_app=current_app)
     if not processors:
         processors = []
     for processor in DEFAULT_PLUGIN_CONTEXT_PROCESSORS:
         self.update(processor(instance, placeholder, self))
     for processor in iterload_objects(get_cms_setting('PLUGIN_CONTEXT_PROCESSORS')):
         self.update(processor(instance, placeholder, self))
     for processor in processors:
         self.update(processor(instance, placeholder, self))
Exemplo n.º 5
0
 def __init__(self, dict, instance, placeholder, processors=None, current_app=None):
     super(PluginContext, self).__init__(dict, current_app=current_app)
     if not processors:
         processors = []
     for processor in DEFAULT_PLUGIN_CONTEXT_PROCESSORS:
         self.update(processor(instance, placeholder))
     for processor in iterload_objects(settings.CMS_PLUGIN_CONTEXT_PROCESSORS):
         self.update(processor(instance, placeholder))
     for processor in processors:
         self.update(processor(instance, placeholder))
Exemplo n.º 6
0
 def __init__(self, dict_, instance, placeholder, processors=None, current_app=None):
     dict_ = flatten_context(dict_)
     super(PluginContext, self).__init__(dict_)
     if not processors:
         processors = []
     for processor in DEFAULT_PLUGIN_CONTEXT_PROCESSORS:
         self.update(processor(instance, placeholder, self))
     for processor in iterload_objects(get_cms_setting('PLUGIN_CONTEXT_PROCESSORS')):
         self.update(processor(instance, placeholder, self))
     for processor in processors:
         self.update(processor(instance, placeholder, self))
Exemplo n.º 7
0
 def discover_toolbars(self):
     if self._discovered:
         return
         #import all the modules
     toolbars = get_cms_setting('TOOLBARS')
     if toolbars:
         for cls in iterload_objects(toolbars):
             self.force_register = True
             self.register(cls)
             self.force_register = False
     else:
         load('cms_toolbar')
     self._discovered = True
Exemplo n.º 8
0
 def discover_toolbars(self):
     if self._discovered:
         return
         #import all the modules
     toolbars = get_cms_setting('TOOLBARS')
     if toolbars:
         for cls in iterload_objects(toolbars):
             self.force_register = True
             self.register(cls)
             self.force_register = False
     else:
         load('cms_toolbar')
     self._discovered = True
Exemplo n.º 9
0
    def discover_apps(self):
        self.apphooks = get_cms_setting('APPHOOKS')

        if self.apphooks:
            for cls in iterload_objects(self.apphooks):
                try:
                    self.register(cls, discovering_apps=True)
                except AppAlreadyRegistered:
                    pass

        else:
            load('cms_app')

        self.discovered = True
Exemplo n.º 10
0
 def discover_apps(self):
     if self.discovered:
         return
     #import all the modules
     if settings.CMS_APPHOOKS:
         self.block_register = True
         for cls in iterload_objects(settings.CMS_APPHOOKS):
             self.block_register = False
             self.register(cls)
             self.block_register = True
         self.block_register = False
     else:
         load('cms_app')
     self.discovered = True
Exemplo n.º 11
0
 def discover_apps(self):
     if self.discovered:
         return
     #import all the modules
     if settings.CMS_APPHOOKS:
         self.block_register = True
         for cls in iterload_objects(settings.CMS_APPHOOKS):
             self.block_register = False
             self.register(cls)
             self.block_register = True
         self.block_register = False
     else:
         load('cms_app')
     self.discovered = True
Exemplo n.º 12
0
    def discover_apps(self):
        self.apphooks = get_cms_setting('APPHOOKS')

        if self.apphooks:
            for cls in iterload_objects(self.apphooks):
                try:
                    self.register(cls, discovering_apps=True)
                except AppAlreadyRegistered:
                    pass

        else:
            load('cms_app')

        self.discovered = True
Exemplo n.º 13
0
    def render_plugin(self,
                      instance,
                      context,
                      placeholder=None,
                      editable=False):
        if not placeholder:
            placeholder = instance.placeholder

        instance, plugin = instance.get_plugin_instance()

        if not instance or not plugin.render_plugin:
            return ''

        # we'd better pass a flat dict to template.render
        # as plugin.render can return pretty much any kind of context / dictionary
        # we'd better flatten it and force to a Context object
        # flattening the context means that template must be an engine-specific template object
        # which is guaranteed by get_cached_template if the template returned by
        # plugin._get_render_template is either a string or an engine-specific template object
        context = PluginContext(context, instance, placeholder)
        context = plugin.render(context, instance, placeholder.slot)
        context = flatten_context(context)

        template = plugin._get_render_template(context, instance, placeholder)
        template = self.get_cached_template(template)

        content = template.render(context)

        for processor in iterload_objects(
                get_cms_setting('PLUGIN_PROCESSORS')):
            content = processor(instance, placeholder, content, context)

        if editable:
            content = self.render_editable_plugin(
                instance,
                context=context,
                plugin_class=plugin,
                placeholder=placeholder,
                content=content,
            )
            placeholder_cache = self._rendered_plugins_by_placeholder[
                placeholder.pk]

            plugins_cache = placeholder_cache.setdefault('plugins', [])
            plugins_cache.append(instance)

        for processor in DEFAULT_PLUGIN_PROCESSORS:
            content = processor(instance, placeholder, content, context)
        return content
Exemplo n.º 14
0
 def discover_apps(self):
     if self.discovered:
         return
         #import all the modules
     apphooks = get_cms_setting('APPHOOKS')
     if apphooks:
         self.block_register = True
         for cls in iterload_objects(apphooks):
             self.block_register = False
             self.register(cls)
             self.block_register = True
         self.block_register = False
     else:
         load('cms_app')
     self.discovered = True
Exemplo n.º 15
0
 def save_model(self, request, entry, form, change):
     """Fill the content field with the interpretation
     of the placeholder"""
     context = RequestContext(request)
     #dm
     processors = iterload_objects(settings.CMS_PLUGIN_PROCESSORS)
     plugins = [plugin for plugin in get_plugins(request, entry.content_placeholder)]
     render = render_plugins(plugins, context, entry.content_placeholder)
     content = "".join(render)
     entry.placeholder_render = content
     #entry.placeholder_render = render_placeholder(entry.content_placeholder, context )
     #entry.content = render_placeholder(entry.content_placeholder, context)
     entry.save()
     super(EntryPlaceholderAdmin, self).save_model(
         request, entry, form, change)
Exemplo n.º 16
0
 def discover_apps(self):
     if self.discovered:
         return
         #import all the modules
     apphooks = get_cms_setting('APPHOOKS')
     if apphooks:
         self.block_register = True
         for cls in iterload_objects(apphooks):
             self.block_register = False
             self.register(cls)
             self.block_register = True
         self.block_register = False
     else:
         load('cms_app')
     self.discovered = True
Exemplo n.º 17
0
 def save_model(self, request, entry, form, change):
     """Fill the content field with the interpretation
     of the placeholder"""
     context = RequestContext(request)
     #dm
     processors = iterload_objects(settings.CMS_PLUGIN_PROCESSORS)
     plugins = [
         plugin
         for plugin in get_plugins(request, entry.content_placeholder)
     ]
     render = render_plugins(plugins, context, entry.content_placeholder)
     content = "".join(render)
     entry.placeholder_render = content
     #entry.placeholder_render = render_placeholder(entry.content_placeholder, context )
     #entry.content = render_placeholder(entry.content_placeholder, context)
     entry.save()
     super(EntryPlaceholderAdmin, self).save_model(request, entry, form,
                                                   change)
Exemplo n.º 18
0
    def render_plugin(self, instance, context, placeholder=None, editable=False):
        if not placeholder:
            placeholder = instance.placeholder

        instance, plugin = instance.get_plugin_instance()

        if not instance or not plugin.render_plugin:
            return ''

        # we'd better pass a flat dict to template.render
        # as plugin.render can return pretty much any kind of context / dictionary
        # we'd better flatten it and force to a Context object
        # flattening the context means that template must be an engine-specific template object
        # which is guaranteed by get_cached_template if the template returned by
        # plugin._get_render_template is either a string or an engine-specific template object
        context = PluginContext(context, instance, placeholder)
        context = plugin.render(context, instance, placeholder.slot)
        context = flatten_context(context)

        template = plugin._get_render_template(context, instance, placeholder)
        template = self.get_cached_template(template)

        content = template.render(context)

        for processor in iterload_objects(get_cms_setting('PLUGIN_PROCESSORS')):
            content = processor(instance, placeholder, content, context)

        if editable:
            content = self.render_editable_plugin(
                instance,
                context=context,
                plugin_class=plugin,
                placeholder=placeholder,
                content=content,
            )
            placeholder_cache = self._rendered_plugins_by_placeholder[placeholder.pk]

            plugins_cache = placeholder_cache.setdefault('plugins', [])
            plugins_cache.append(instance)

        for processor in DEFAULT_PLUGIN_PROCESSORS:
            content = processor(instance, placeholder, content, context)
        return content
Exemplo n.º 19
0
def render_plugin(context, instance, placeholder, template, processors=None, current_app=None):
    """
    Renders a single plugin and applies the post processors to it's rendered
    content.
    """
    if not processors:
        processors = []
    if isinstance(template, six.string_types):
        content = render_to_string(template, context_instance=context)
    elif isinstance(template, Template):
        content = template.render(context)
    else:
        content = ''
    for processor in iterload_objects(get_cms_setting('PLUGIN_PROCESSORS')):
        content = processor(instance, placeholder, content, context)
    for processor in processors:
        content = processor(instance, placeholder, content, context)
    for processor in DEFAULT_PLUGIN_PROCESSORS:
        content = processor(instance, placeholder, content, context)
    return content
Exemplo n.º 20
0
def render_plugin(context, instance, placeholder, template, processors=None, current_app=None):
    """
    Renders a single plugin and applies the post processors to it's rendered
    content.
    """
    if current_app:
        context["request"].current_app = current_app
    if not processors:
        processors = []
    if isinstance(template, six.string_types):
        content = render_to_string(template, flatten_context(context))
    elif isinstance(template, Template) or (
        hasattr(template, "template") and hasattr(template, "render") and isinstance(template.template, Template)
    ):
        content = template.render(context)
    else:
        content = ""
    for processor in iterload_objects(get_cms_setting("PLUGIN_PROCESSORS")):
        content = processor(instance, placeholder, content, context)
    for processor in processors:
        content = processor(instance, placeholder, content, context)
    for processor in DEFAULT_PLUGIN_PROCESSORS:
        content = processor(instance, placeholder, content, context)
    return content
 def test_iterators(self):
     self.assertIsInstance(django_load.iterload('menus'), Iterator)
     toolbars = get_cms_setting('TOOLBARS')
     self.assertIsInstance(django_load.iterload_objects(toolbars), Iterator)