tslumen.jinja_utils module

Jinja util functions

tslumen.jinja_utils.create_jinja_env(paths: Optional[List[str]], search_paths: Optional[List[str]], pkg_path: str, check: Optional[str] = None)jinja2.environment.Environment[source]
tslumen.jinja_utils.filter_autoformat(value: Any, **kwargs: Any)str[source]

Jinja filter to try and autoformat a given value based on its data type.

Parameters
  • value (Any) – Object to format.

  • **kwargs (Any) – Optional keyword arguments to pass along to the chosen formatter.

Returns

Formatted object.

Return type

str

tslumen.jinja_utils.filter_dateformat(value: Any, fmt: str = '{:%Y-%m-%d %H:%M:%S}', freq: Optional[str] = None)str[source]

Jinja filter to format a datetime. If a frequency is provided, uses it to obtain the best format, else defers to fmt.

Parameters
  • value (Any) – Datetime to format.

  • fmt (str) – The datetime format to default to.

  • freq (Optional[str]) – The respective frequency.

Returns

Formatted datetime.

Return type

str

tslumen.jinja_utils.filter_html(value: Any)str[source]

Jinja filter to try and get an HTML representation of an object while respecting the preferred precedence: obj.html, obj._repr_html_, str(obj).

Parameters

value (Any) – The object to represent as HTML.

Returns

Object’s HTML representation.

Return type

str

tslumen.jinja_utils.filter_idhtml(value: Any)str[source]

Sanitizes a string to be a valid HTML id attribute.

Parameters

value (Any) – Value to use as ID.

Returns

Sanitized (HTML safe) ID.

Return type

str

tslumen.jinja_utils.filter_islist(value: Any)bool[source]

Checks if an object is list-like.

Parameters

value (Any) – Value to be checked.

Returns

Whether value is a list or a tuple.

Return type

bool

tslumen.jinja_utils.filter_numberformat(value: Any)str[source]

Jinja filter to auto format numbers

Parameters

value (Any) – Number to format.

Returns

Formatted number.

Return type

str

tslumen.jinja_utils.format_date_freq(freq: Optional[str] = None)str[source]
Parameters

freq (Optional[str]) – Time series frequency (follow’s Panda’s convention).

Returns

Ideal datetime format string based on the frequency.

Return type

str

tslumen.jinja_utils.format_number(value: Any)Tuple[str, int][source]
Parameters

value (Any) – A number.

Returns

Format string; Divisor – value should be divided by this before formatting.

Return type

str, int