orangeqs.juice.reporting.templating_engine.utilities#

Utilities for the Jinja2 templating engine used in the reporting module.

Module Contents#

Functions#

set_templating_env

Set the global Jinja2 templating environment.

get_templating_env

Retrieve the current Jinja2 templating environment.

set_default_templating_env

Initialize and sets the default Jinja2 templating environment for reporting.

add_directory_to_templating_env

Add a new directory to the existing Jinja2 templating environment’s loader.

shallow_dump

Dump a pydantic model to a dictionary.

add_filter_to_templating_env

Add a custom filter to the Jinja2 templating environment.

API#

orangeqs.juice.reporting.templating_engine.utilities.set_templating_env(value: jinja2.Environment) None#

Set the global Jinja2 templating environment.

This function is typically called during module initialization to configure the environment with loaders, filters, and other settings.

Parameters#

  • value (Environment): A fully configured Jinja2 Environment instance.

orangeqs.juice.reporting.templating_engine.utilities.get_templating_env() jinja2.Environment#

Retrieve the current Jinja2 templating environment.

Returns#

  • (Environment): The current Jinja2 Environment instance, or None if it has not been set.

orangeqs.juice.reporting.templating_engine.utilities.set_default_templating_env() jinja2.Environment#

Initialize and sets the default Jinja2 templating environment for reporting.

This function constructs a Jinja2 Environment using a ChoiceLoader that prioritizes:

  1. A FileSystemLoader pointing to the module’s output_dir directory.

  2. A PackageLoader for built-in templates located in the orangeqs.juice.reporting package.

It also registers all custom filters defined in the _filters module.

The resulting environment is stored globally via set_templating_env() for reuse across the module.

Returns#

  • (Environment): A fully configured Jinja2 Environment instance.

orangeqs.juice.reporting.templating_engine.utilities.add_directory_to_templating_env(new_path: str) None#

Add a new directory to the existing Jinja2 templating environment’s loader.

New loaders are added with higher priority than existing ones, meaning templates in the new directory will be found before those in previously configured directories.

Parameters#

  • new_path (str): The filesystem path to the new template directory.

orangeqs.juice.reporting.templating_engine.utilities.shallow_dump(model: pydantic.BaseModel, /) dict[str, Any]#

Dump a pydantic model to a dictionary.

While keeping submodels as models and not converting them to dictionaries. Standard BaseModel.model_dump() does not support this.

orangeqs.juice.reporting.templating_engine.utilities.add_filter_to_templating_env(filter: str) None#

Add a custom filter to the Jinja2 templating environment.

The filter is imported from a dotted path and added to the environment’s filters.

Parameters#

  • filter (str): The dotted path to a filter function to be added to the templating environment.