diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 72380bb04..d5a24a9a5 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -6,6 +6,10 @@ FlexMeasures Changelog v0.5.0 | May XX, 2021 =========================== +New features +----------- +* Allow plugins to overwrite UI routes and customise the teaser on the login form [see `PR #106 `_] + Infrastructure / Support ---------------------- * Make assets use MW as their default unit and enforce that in CLI, as well (API already did) [see `PR #108 `_] diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index 8fbf02385..ba65e2a9c 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -49,6 +49,7 @@ All else that is needed for this showcase (not shown here) is ``/ou # Showcase: Adding a view + @our_client_bp.route('/') @our_client_bp.route('/metrics') @login_required def metrics(): @@ -75,6 +76,7 @@ All else that is needed for this showcase (not shown here) is ``/ou print(f"I am a CLI command, part of FlexMeasures: {current_app}") +.. note:: You can overwrite FlexMeasures routes here. In our example above, we set the root route ``/``. FlexMeasures registers plugin routes before its own, so in this case visiting the root URL of your app will display this plugged-in view (the same you'd see at `/metrics`). .. note:: Plugin views can also be added to the FlexMeasures UI menu ― just name them in the config setting :ref:`menu-config`. @@ -93,4 +95,28 @@ This can be done if you put the plugin path on the import path. Do it like this HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) - from my_other_file import my_function \ No newline at end of file + from my_other_file import my_function + + +Customising the login teaser +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +FlexMeasures shows an image carousel next to its login form (see ``ui/templates/admin/login_user.html``). + +You can overwrite this content by adding your own login template and defining the ``teaser`` block yourself, e.g.: + +.. code-block:: html + + {% extends "admin/login_user.html" %} + + {% block teaser %} + +

Welcome to my plugin!

+ + {% endblock %} + +Place this template file in the template folder of your plugin blueprint (see above). Your template must have a different filename than "login_user", so FlexMeasures will find it properly! + +Finally, add this config setting to your FlexMeasures config file (using the template filename you chose, obviously): + + SECURITY_LOGIN_USER_TEMPLATE = "my_user_login.html" diff --git a/flexmeasures/api/common/utils/api_utils.py b/flexmeasures/api/common/utils/api_utils.py index dbbcca910..ac729707d 100644 --- a/flexmeasures/api/common/utils/api_utils.py +++ b/flexmeasures/api/common/utils/api_utils.py @@ -360,7 +360,7 @@ def get_generic_asset( def save_to_db( timed_values: List[Union[Power, Price, Weather]], forecasting_jobs: List[Job] ) -> ResponseTuple: - """Put the timed values into the database and create forecasting jobs. + """Put the timed values into the database and enqueue forecasting jobs. Data can only be replaced on servers in play mode. diff --git a/flexmeasures/app.py b/flexmeasures/app.py index c2ef442f2..9918b6d9e 100644 --- a/flexmeasures/app.py +++ b/flexmeasures/app.py @@ -98,17 +98,22 @@ def create(env: Optional[str] = None, path_to_config: Optional[str] = None) -> F register_api_at(app) + # Register plugins + + from flexmeasures.utils.app_utils import register_plugins + + register_plugins(app) + # Register the UI + # If plugins registered routes already (e.g. "/"), + # they have precedence (first registration wins). from flexmeasures.ui import register_at as register_ui_at register_ui_at(app) - from flexmeasures.utils.app_utils import register_plugins - - register_plugins(app) - # Profile endpoints (if needed, e.g. during development) + @app.before_request def before_request(): if app.config.get("FLEXMEASURES_PROFILE_REQUESTS", False): diff --git a/flexmeasures/ui/templates/admin/login_user.html b/flexmeasures/ui/templates/admin/login_user.html index a8e2a74d1..557fc9028 100644 --- a/flexmeasures/ui/templates/admin/login_user.html +++ b/flexmeasures/ui/templates/admin/login_user.html @@ -40,6 +40,7 @@

Interested in a demo?

{% endif %}
+ {% block teaser %}

The FlexMeasures Platform

+ {% endblock teaser %}