Skip to content

Commit cace75e

Browse files
committed
Backport PR #2006: Feat: redirect to RTD if local docs missing (#2006)
* feat: still link Swagger to Sphinx, but use the external RTD stable docs in case local docs are missing (not built) Signed-off-by: F.N. Claessen <claessen@seita.nl> * Revert "feat: still link Swagger to Sphinx, but use the external RTD stable docs in case local docs are missing (not built)" This reverts commit 52565a3. * feat: redirect to RTD in case of missing local docs (not built) Signed-off-by: F.N. Claessen <claessen@seita.nl> * docs: changelog entry Signed-off-by: F.N. Claessen <claessen@seita.nl> --------- Signed-off-by: F.N. Claessen <claessen@seita.nl> (cherry picked from commit b6d44d0)
1 parent 94812a1 commit cace75e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

documentation/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ v0.31.1 | March XX, 2026
99

1010
Bugfixes
1111
-----------
12-
- Add missing field documentation for ``aggregate-power`` and ``state-of-charge`` fields, which can be used to reference a sensor on which to record extra scheduling results [see `PR #2003 <https://www.github.com/FlexMeasures/flexmeasures/pull/2003>`_]
12+
- Add missing field documentation for ``aggregate-power`` and ``state-of-charge`` fields, which can be used to reference a sensor on which to record extra scheduling results [see `PR #2003 <https://www.github.com/FlexMeasures/flexmeasures/pull/2003>`_ and `PR #2006 <https://www.github.com/FlexMeasures/flexmeasures/pull/2006>`_]
1313

1414

1515
v0.31.0 | February 28, 2026

flexmeasures/ui/error_handlers.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Error views for UI purposes."""
22

3-
from flask import Flask
3+
from flask import Flask, request, redirect
44
from werkzeug.exceptions import BadRequest, InternalServerError, HTTPException
55

66
from flexmeasures.ui.utils.view_utils import render_flexmeasures_template
@@ -60,6 +60,33 @@ def handle_bad_request(e: BadRequest):
6060

6161

6262
def handle_not_found(e):
63+
"""Handle 404 errors for the UI.
64+
65+
Special handling:
66+
- If the request is for documentation under
67+
``/ui/static/documentation/html``, redirect to the
68+
corresponding ReadTheDocs URL.
69+
- Preserves query string parameters.
70+
71+
Examples
72+
--------
73+
/ui/static/documentation/html/index.html
74+
-> https://flexmeasures.readthedocs.io/stable/index.html
75+
76+
/ui/static/documentation/html/search.html?q=commitments
77+
-> https://flexmeasures.readthedocs.io/stable/search.html?q=commitments
78+
"""
79+
docs_prefix = "/ui/static/documentation/html"
80+
81+
if request.path.startswith(docs_prefix):
82+
# remove prefix and any leading slash
83+
page = request.path[len(docs_prefix) :].lstrip("/")
84+
# include query string if present
85+
query = f"?{request.query_string.decode()}" if request.query_string else ""
86+
return redirect(
87+
f"https://flexmeasures.readthedocs.io/stable/{page}{query}", 302
88+
)
89+
6390
return (
6491
render_flexmeasures_template(
6592
"error.html",

0 commit comments

Comments
 (0)