orangeqs.juice.reporting.templating_engine.utilities#
Utilities for the Jinja2 templating engine used in the reporting module.
Module Contents#
Functions#
Set the global Jinja2 templating environment. |
|
Retrieve the current Jinja2 templating environment. |
|
Initialize and sets the default Jinja2 templating environment for reporting. |
|
Add a new directory to the existing Jinja2 templating environment’s loader. |
|
Dump a pydantic model to a dictionary. |
|
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
Environmentusing aChoiceLoaderthat prioritizes:A
FileSystemLoaderpointing to the module’soutput_dirdirectory.A
PackageLoaderfor built-in templates located in theorangeqs.juice.reportingpackage.
It also registers all custom filters defined in the
_filtersmodule.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.