Renderer (feincms3.renderer)

exception feincms3.renderer.PluginNotRegisteredError[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.

copy()[source]

Return a shallow copy of the renderer

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(*, fetch=True)[source]

Return a list of all registered plugin classes

By default and because of backwards compatibility concerns the method only returns plugins which have been registered for fetching.

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'}, fetch=True)[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 three 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).

  • fetch = True: By default a plugin is fetched from the database; setting this to False allows registering plugin classes which shouldn’t be fetched from the database.

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.

render_regions(*, regions, contents, context)[source]

Render multiple regions.

This method should return a dictionary.

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.

unregister(*plugins, keep=())[source]

Unregister plugins

You can either pass a list of plugins which should be unregistered:

renderer.unregister(HTML, RichText)

Or you can specify which plugins should be kept:

renderer.unregister(keep=(HTML, RichText))

You cannot do both at the same time.

Plugins can either be the plugin classes themselves or base classes.

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 %}