flexmeasures.utils.app_utils

Utils for serving the FlexMeasures app

Functions

flexmeasures.utils.app_utils.find_first_applicable_config_entry(configs: list, setting_name: str, app: Flask | None = None) str | None
flexmeasures.utils.app_utils.init_sentry(app: Flask)

Configure Sentry. We need the app to read the Sentry DSN from configuration, and also to send some additional meta information.

flexmeasures.utils.app_utils.parse_config_entry_by_account_roles(config: str | tuple[str, list[str]], setting_name: str, app: Flask | None = None) str | None

Parse a config entry (which can be a string, e.g. “dashboard” or a tuple, e.g. (“dashboard”, [“MDC”])). In the latter case, return the first item (a string) only if the current user’s account roles match with the list of roles in the second item. Otherwise, return None.

flexmeasures.utils.app_utils.root_dispatcher()

Re-routes to root views fitting for the current user, depending on the FLEXMEASURES_ROOT_VIEW setting.

flexmeasures.utils.app_utils.set_secret_key(app, filename='secret_key')

Set the SECRET_KEY or exit.

We first check if it is already in the config.

Then we look for it in environment var SECRET_KEY.

Finally, we look for filename in the app’s instance directory.

If nothing is found, we print instructions to create the secret and then exit.