Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable plugins to decide which view is shown after logging in. #106

8 changes: 8 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -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 <http://www.github.com/SeitaBV/flexmeasures/pull/106>`_]


v0.4.0 | April XX, 2021
===========================

Expand Down
27 changes: 26 additions & 1 deletion documentation/dev/plugins.rst
Expand Up @@ -75,6 +75,7 @@ All else that is needed for this showcase (not shown here) is ``<some_folder>/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`.

Expand All @@ -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
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 %}

<h1>Welcome to my plugin!</h1>

{% 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"
2 changes: 1 addition & 1 deletion flexmeasures/api/common/utils/api_utils.py
Expand Up @@ -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.

Expand Down
13 changes: 9 additions & 4 deletions flexmeasures/app.py
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions flexmeasures/ui/templates/admin/login_user.html
Expand Up @@ -40,6 +40,7 @@ <h2>Interested in a demo?</h2>
{% endif %}
</div>
<div class="col-sm-8">
{% block teaser %}
<h1>The FlexMeasures Platform</h1>
<div class="carousel-container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
Expand Down Expand Up @@ -86,6 +87,7 @@ <h1>The FlexMeasures Platform</h1>
</a>
</div>
</div>
{% endblock teaser %}
</div>
</div>
</div>
Expand Down