From 7d57af56ad5fca80ee797a68425a3259b51157c7 Mon Sep 17 00:00:00 2001 From: nhoening Date: Thu, 29 Apr 2021 07:45:48 +0000 Subject: [PATCH 1/5] Create draft PR for #100 From 944ee9818e5890763c7ae98879a15d3af36df020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 29 Apr 2021 10:46:26 +0200 Subject: [PATCH 2/5] register plugins before UI, so that plugin routes have precedence --- flexmeasures/api/common/utils/api_utils.py | 2 +- flexmeasures/app.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/flexmeasures/api/common/utils/api_utils.py b/flexmeasures/api/common/utils/api_utils.py index e56c15952..4c166d3b2 100644 --- a/flexmeasures/api/common/utils/api_utils.py +++ b/flexmeasures/api/common/utils/api_utils.py @@ -372,7 +372,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): From d3a9a160d05e3b83fbdfc76e004356a0c6b6bd89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 29 Apr 2021 11:20:53 +0200 Subject: [PATCH 3/5] allow to overwrite the teaser on the login page & document how that works --- documentation/dev/plugins.rst | 27 ++++++++++++++++++- .../ui/templates/admin/login_user.html | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index 8fbf02385..42b0ab358 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -75,6 +75,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, for example the root route ``/``, as FlexMeasures registers plugin routes before its own. .. note:: Plugin views can also be added to the FlexMeasures UI menu ― just name them in the config setting :ref:`menu-config`. @@ -93,4 +94,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/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 %}
From 6421e412e0624f6555c30038be2545312a403b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 29 Apr 2021 11:52:26 +0200 Subject: [PATCH 4/5] add changelog entry --- documentation/changelog.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index ff83f33a6..0a7b04d12 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -3,6 +3,14 @@ FlexMeasures Changelog ********************** +v0.5.0 | May XX, 2021 +=========================== + +Infrastructure / Support +---------------------- +* Allow plugins to overwrite UI routes and customise the teaser on the login form [see `PR #106 `_] + + v0.4.0 | April XX, 2021 =========================== From b1355f4c224aec67aaba2a269e2c553ac61a9323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sat, 1 May 2021 22:31:33 +0200 Subject: [PATCH 5/5] update the plugin docs to showcase overwriting the '/' route --- documentation/dev/plugins.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index 42b0ab358..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,7 +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, for example the root route ``/``, as FlexMeasures registers plugin routes before its own. +.. 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`.