flexmeasures.ui.crud.assets

Functions

flexmeasures.ui.crud.assets.get_assets_by_account(account_id: int | str | None) list[GenericAsset]
flexmeasures.ui.crud.assets.process_internal_api_response(asset_data: dict, asset_id: int | None = None, make_obj=False) GenericAsset | dict

Turn data from the internal API into something we can use to further populate the UI. Either as an asset object or a dict for form filling.

If we add other data by querying the database, we make sure the asset is not in the session afterwards.

flexmeasures.ui.crud.assets.user_can_create_assets() bool
flexmeasures.ui.crud.assets.user_can_delete(asset) bool
flexmeasures.ui.crud.assets.with_options(form: AssetForm | NewAssetForm) AssetForm | NewAssetForm

Classes

class flexmeasures.ui.crud.assets.AssetCrudUI

These views help us offer a Jinja2-based UI. The main focus on logic is the API, so these views simply call the API functions, and deal with the response. Some new functionality, like fetching accounts and asset types, is added here.

delete_with_data(id: str)

Delete via /assets/delete_with_data/<id>

get(id: str, **kwargs)

GET from /assets/<id> where id can be ‘new’ (and thus the form for asset creation is shown) The following query parameters are supported (should be used only together):

  • start_time: minimum time of the events to be shown

  • end_time: maximum time of the events to be shown

index(msg='')

GET from /assets

List the user’s assets. For admins, list across all accounts.

owned_by(account_id: str)

/assets/owned_by/<account_id>

post(id: str)

POST to /assets/<id>, where id can be ‘create’ (and thus a new asset is made from POST data) Most of the code deals with creating a user for the asset if no existing is chosen.

status(id: str)

GET from /assets/<id>/status to show the staleness of the asset’s sensors.

class flexmeasures.ui.crud.assets.AssetForm(*args, **kwargs)

The default asset form only allows to edit the name and location.

process_api_validation_errors(api_response: dict)

Process form errors from the API for the WTForm

to_json() dict

turn form data into a JSON we can POST to our internal API

validate_on_submit()

Call validate() only if the form is submitted. This is a shortcut for form.is_submitted() and form.validate().

class flexmeasures.ui.crud.assets.NewAssetForm(*args, **kwargs)

Here, in addition, we allow to set asset type and account.