Renderer (feincms3.renderer)#

exception feincms3.renderer.PluginNotRegistered[source]#

Exception raised when encountering a plugin which isn’t known to the renderer.

class feincms3.renderer.RegionRenderer[source]#

The region renderer knows how to render single plugins and also complete regions.

The basic usage is to instantiate the region renderer, register plugins and render a full region with it.

handle(plugins, context)[source]#

Runs the handle_<subregion> handler for the head of the plugins deque.

This method requires that a matching handler for all values returned by self.subregion() exists.

You probably want to call this method when overriding the rendering of a complete region.

handle_default(plugins, context)[source]#

Renders plugins from the queue as long as there are plugins belonging to the default subregion.

marks(plugin)[source]#

Return the marks of a plugin instance

plugins()[source]#

Return a list of all registered plugin classes

regions_from_contents(contents, **kwargs)[source]#

Return an opaque object encapsulating content_editor.contents.Contents and the logic required to render them.

All you need to know is that the return value has a regions attribute containing a list of regions and a render method accepting a region key and a context instance.

regions_from_item(item, /, *, inherit_from=None, timeout=None, **kwargs)[source]#

Return an opaque object, see regions_from_contents()

Automatically caches the return value if timeout is truthy. The default cache key only takes the item’s class and primary key into account. You may have to override the cache key by passing cache_key if you’re doing strange^Wadvanced things.

register(plugin, renderer, /, subregion='default', marks={'default'})[source]#

Register a plugin class

The renderer is either a static value or a function which always receives two arguments: The plugin instance and the context. When using {% render_region %} and the Django template language the context will be a Django template Context (or even RequestContext) instance.

The two optional keyword arguments’ are:

  • subregion: str = "default": The subregion for this plugin as a string or as a callable accepting a single plugin instance. A matching handle_<subregion> callable has to exist on the region renderer instance or rendering will crash loudly.

  • marks: Set[str] = {"default"}: The marks of this plugin. Marks only have the meaning you assign to them. Marks are preferrable to running isinstance on plugin instances especially when using the same region renderer class for different content types (e.g. pages and blog articles).

register_string_renderer(plugin, renderer)[source]#

Backwards compatibility for TemplatePluginRenderer. It is deprecated, don’t use in new code.

register_template_renderer(plugin, template_name, context=<function default_context>)[source]#

Backwards compatibility for TemplatePluginRenderer. It is deprecated, don’t use in new code.

render_plugin(plugin, context)[source]#

Render a single plugin using the registered renderer

render_plugin_in_context(plugin, context=None)[source]#

Backwards compatibility for TemplatePluginRenderer. It is deprecated, don’t use in new code.

render_region(*, region, contents, context)[source]#

Render one region.

subregion(plugin)[source]#

Return the subregion of a plugin instance

takewhile_mark(plugins, mark)[source]#

Yield all plugins from the head of the plugins deque as long as their marks include mark.

takewhile_subregion(plugins, subregion)[source]#

Yield all plugins from the head of the plugins deque as long as their subregion equals subregion.

class feincms3.renderer.TemplatePluginRenderer(*args, **kwargs)[source]#

TemplatePluginRenderer is deprecated, use RegionRenderer.

feincms3.renderer.default_context(plugin, context)[source]#

Return the default context for plugins rendered with a template, which simply is a single variable named plugin containing the plugin instance.

feincms3.renderer.render_in_context(context, template, local_context=None)[source]#

Render using a template rendering context

This utility avoids the problem of render_to_string requiring a dict and not a full-blown Context instance which would needlessly burn CPU cycles.

feincms3.renderer.template_renderer(template_name, local_context=<function default_context>, /)[source]#

Build a renderer for the region renderer which uses a template (or a list of templates) and optionally a local context function. The context contains the site-wide context variables too when invoked via {% render_region %}