ContextPlugin reference#

The complete ContextPlugin interface looks like this:

class tattler.server.pluginloader.ContextPlugin#

Base class for Context plug-ins, which extend or override context variables for templates.

A Context plug-in may choose to indicate whether it should be run – for each notification request – by implementing the processing_required() method, which otherwise defaults to True.

This enables resource-intensive plug-ins to only “fire” when necessary, e.g. based on the event being notified, the recipient, or more.

If multiple context plug-ins are provided, tattler “pipelines” them, i.e. it passes the its native context to the first, and the resulting context to each subsequent context plug-in.

New in version 1.2.0: This was named ContextTattlerPlugin in tattler versions up to 1.1.1, and was renamed in version 1.2.0 for simplicity and symmetry with AddressbookPlugin.

Version 1.2.0 retains name ContextTattlerPlugin as an alias to this class for backward compatibility, but tattler will produce a deprecation warning at runtime for plug-ins that still inherit from ContextTattlerPlugin.

process(context)#

Run the plug-in to generate new context data.

The latest (previous) context is passed as input to this method, allowing the method to add, change or remove variables from it.

Parameters:

context (Mapping[str, Any]) – The latest context resulting from the previous plug-in, or tattler’s native context for the first-running context plug-in.

Return type:

Mapping[str, Any]

Returns:

The generated context to either feed to the template, or to the next context plug-in in the chain.

processing_required(context)#

Return whether this plugin should be called, based on the context.

Implementing this method is optional, and defaults to True otherwise.

Implement this only if you’re writing a very resource-intensive context plug-in.

In most scenarios, the rate of notifications is low enough to have the risk and complications of introducing this dynamic behavior vastly exceed the benefit of the spared CPU cycles.

If you do implement this, try to keep your logic simple and based on deterministic variables (like the scope name or event name) rather than more complex, less predictable data like the presence of some variable from previous plug-ins.

Parameters:

context (Mapping[str, Any]) – The latest context resulting from the previous plug-in, or tattler’s native context for the first-running context plug-in.

Return type:

bool

Returns:

Whether process() should be called for this plug-in.

class tattler.server.pluginloader.ContextTattlerPlugin#

Compatibility alias to class ContextPlugin, renamed in Tattler version 1.1.1.

Deprecated since version 1.2.0: Use class ContextPlugin instead. Name ContextTattlerPlugin is retained as an alias for backward compatibility, but tattler will log a deprecation warning at runtime for plug-ins still inheriting from this name.

process(context)#

Run the plug-in to generate new context data.

The latest (previous) context is passed as input to this method, allowing the method to add, change or remove variables from it.

Parameters:

context (Mapping[str, Any]) – The latest context resulting from the previous plug-in, or tattler’s native context for the first-running context plug-in.

Return type:

Mapping[str, Any]

Returns:

The generated context to either feed to the template, or to the next context plug-in in the chain.

processing_required(context)#

Return whether this plugin should be called, based on the context.

Implementing this method is optional, and defaults to True otherwise.

Implement this only if you’re writing a very resource-intensive context plug-in.

In most scenarios, the rate of notifications is low enough to have the risk and complications of introducing this dynamic behavior vastly exceed the benefit of the spared CPU cycles.

If you do implement this, try to keep your logic simple and based on deterministic variables (like the scope name or event name) rather than more complex, less predictable data like the presence of some variable from previous plug-ins.

Parameters:

context (Mapping[str, Any]) – The latest context resulting from the previous plug-in, or tattler’s native context for the first-running context plug-in.

Return type:

bool

Returns:

Whether process() should be called for this plug-in.