Utilities for views


flexmeasures.ui.utils.view_utils.accountname(account_id) str
flexmeasures.ui.utils.view_utils.asset_icon_name(asset_type_name: str) str

Icon name for this asset type.

This can be used for UI html templates made with Jinja. ui.__init__ makes this function available as the filter “asset_icon”.

For example:

<i class={{ asset_type.name | asset_icon }}></i>

becomes (for a battery):

<i class=”icon-battery”></i>

flexmeasures.ui.utils.view_utils.get_git_description() tuple[str, int, str]

Get information about the SCM (git) state if possible (if a .git directory exists).

Returns the latest git version (tag) as a string, the number of commits since then as an int and the current commit hash as string.

flexmeasures.ui.utils.view_utils.render_flexmeasures_template(html_filename: str, **variables)

Render template and add all expected template variables, plus the ones given as **variables.

flexmeasures.ui.utils.view_utils.set_session_variables(*var_names: str)

Store request values as session variables, for a consistent UX across UI page loads.

>>> set_session_variables("event_starts_after", "event_ends_before", "chart_type")
flexmeasures.ui.utils.view_utils.username(user_id) str