From 11ec11ed09c77828dc7d6c4e71bb36aaa23b849f Mon Sep 17 00:00:00 2001 From: nhoening Date: Thu, 15 Jul 2021 10:04:29 +0000 Subject: [PATCH 1/5] Create draft PR for #140 From d2f337d62363e5a7b14cbfbd19a1d5d7286aa83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 15 Jul 2021 17:30:12 +0200 Subject: [PATCH 2/5] add documentation on how plugins can show their custom favicons --- documentation/changelog.rst | 1 + documentation/dev/plugins.rst | 37 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 28555a600..15346eb73 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -18,6 +18,7 @@ Infrastructure / Support * Add possibility to send errors to Sentry [see `PR #143 `_] * Add CLI task to monitor if tasks ran successfully and recently enough [see `PR #146 `_] +* Document how to use a custom favicon in plugins [see `PR #152 `_] v0.5.0 | June 7, 2021 diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index 3606a2ed4..a0bdf338b 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -121,7 +121,7 @@ Starting the template with ``{% extends "base.html" %}`` integrates your page co We'd name this file ``our_client_base.html``. Then, we'd extend our page template from ``our_client_base.html``, instead of ``base.html``. -Using other files in your plugin +Using other code files in your plugin ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Say you want to include other Python files in your plugin, importing them in your ``__init__.py`` file. @@ -138,6 +138,41 @@ This can be done if you put the plugin path on the import path. Do it like this from my_other_file import my_function +Using a custom favicon icon +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The favicon might be an important part of your customisation. You probably want your logo to be used. + +First, your blueprint needs to know about a folder with static content (this is fairly common ― it's also where you'd put your own CSS or JavaScript files): + +.. code-block:: python + + our_client_bp = Blueprint( + "our_client", + "our_client", + static_folder="our_client/ui/static", + static_url_path="/ui/static", + ) + +Put your icon file in that folder. The exact paths may depend on how you set your plugin directories up, but this is how a blueprint living in its own directory could work. + +Then, overwrite the ``/favicon.ico`` route which FlexMeasures uses to get the favicon from: + +.. code-block:: python + + from flask import send_from_directory + + @our_client_bp.route("/favicon.ico") + def favicon(): + return send_from_directory( + our_client_bp.static_folder, + "img/favicon.png", + mimetype="image/png", + ) + +Here we assume your favicon is a PNG file. You can also use a classic `.ico` file, then your mime type probably works best as ``image/vnd.microsoft.icon``. + + Validating arguments in your CLI commands with marshmallow ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 61a0b0852d8e3ae4fdd209e4cb4cb9523b97ee91 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 19 Jul 2021 14:30:43 +0200 Subject: [PATCH 3/5] Do not override app's static url path --- documentation/dev/plugins.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index a0bdf338b..f7abb0d2d 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -10,7 +10,7 @@ A FlexMeasures plugin works as a `Flask Blueprint Date: Mon, 19 Jul 2021 15:15:42 +0200 Subject: [PATCH 4/5] Plural to singular --- documentation/dev/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index f7abb0d2d..22e225dd9 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -153,7 +153,7 @@ First, your blueprint needs to know about a folder with static content (this is static_folder="our_client/ui/static", ) -Put your icon file in that folder. The exact paths may depend on how you set your plugin directories up, but this is how a blueprint living in its own directory could work. +Put your icon file in that folder. The exact path may depend on how you set your plugin directories up, but this is how a blueprint living in its own directory could work. Then, overwrite the ``/favicon.ico`` route which FlexMeasures uses to get the favicon from: From e7819b124ae10ff2ed33abfff13157bc725fa768 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Tue, 20 Jul 2021 10:26:48 +0200 Subject: [PATCH 5/5] Update MIME type for ico extension --- documentation/dev/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index 22e225dd9..59044bd93 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -169,7 +169,7 @@ Then, overwrite the ``/favicon.ico`` route which FlexMeasures uses to get the fa mimetype="image/png", ) -Here we assume your favicon is a PNG file. You can also use a classic `.ico` file, then your mime type probably works best as ``image/vnd.microsoft.icon``. +Here we assume your favicon is a PNG file. You can also use a classic `.ico` file, then your mime type probably works best as ``image/x-icon``. Validating arguments in your CLI commands with marshmallow