flexmeasures.ui.views.assets.utils
Functions
- flexmeasures.ui.views.assets.utils.add_child_asset(asset: GenericAsset, assets: list) list
Add a child asset to the current assets list. This function is used to add a child asset to the current asset in the list of assets.
- Parameters:
asset – The current asset to be used as parent.
assets – The list of assets.
- flexmeasures.ui.views.assets.utils.deleted_sensor_references_toast(asset: GenericAsset) Markup | None
The toast an asset’s pages show while its flex-config has fields whose sensor was deleted.
Deleting a sensor leaves the rest of each reference to it in place, such as its default and bounds, but the field needs a new sensor, and until it has one, saving its flex-config is refused. So each page of the asset points the user at the editor for it.
Only a user who can edit the asset’s flex-config is pointed at the editor, as no one else can save the fix.
- Returns:
The toast’s message, or None if no field lost its sensor, or the user cannot fix it.
- flexmeasures.ui.views.assets.utils.editor_paths_and_url(asset: GenericAsset, config_name: str, paths: list[str]) tuple[list[str], str]
Order the paths of fields whose sensor was deleted, and link to the editor for them.
Top-level fields come first, as these are what the flex-context editor can open directly, so the link opens it on the first of them. The flex-model editor is on the asset’s Properties page, which the link goes to.
- Parameters:
config_name – “flex-context” or “flex-model”.
- Returns:
The ordered paths, and the editor’s URL.
- flexmeasures.ui.views.assets.utils.get_asset_by_id_or_raise_notfound(asset_id: str) GenericAsset
find an show existing asset or raise NotFound
- flexmeasures.ui.views.assets.utils.get_inherited_flex_context(asset: GenericAsset) dict[str, dict]
Collect the flex-context fields the asset would inherit from its ancestors.
Fields set on the asset itself are not excluded here: the flex-context editor decides at render time which of these are shadowed by local fields, so that removing a local field immediately reveals the inherited value it was shadowing.
- Returns:
Dictionary mapping each ancestor-defined field name to a dictionary with the field’s
valueand theasset_idandasset_nameof the defining ancestor.
Values set on an ancestor the viewer may not read (in another organisation) are left out, with
hiddenset, so the page can say a value is inherited without showing it. Scheduling still uses them.
- flexmeasures.ui.views.assets.utils.get_list_assets_chart(asset: GenericAsset, base_asset: GenericAsset, parent_depth=0, child_depth=0, look_for_child=False, is_head=False) list[dict]
Recursively builds a tree of assets from a given asset and its parents and children up to a certain depth.
- Args:
asset: The asset to start the recursion from base_asset: The asset that is the base of the chart parent_depth: The current depth of the parents hierarchy child_depth: The current depth of the children hierarchy look_for_child: If True, start looking for children of the current asset is_head: If True, the current asset is the head of the chart
- Returns:
A list of dictionaries representing the assets in the tree
- flexmeasures.ui.views.assets.utils.readable_site_asset(asset: GenericAsset) GenericAsset
The highest ancestor of the asset (or the asset itself) that the viewer may read.
Usually the site asset, unless the asset tree goes up into an organisation the viewer may not see.
- flexmeasures.ui.views.assets.utils.serialize_asset(asset: GenericAsset, is_head=False) dict
A node in the asset tree for assets the viewer may not read: no name, link, type or sensors.