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

Fix get chart #223

Merged
merged 3 commits into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -18,6 +18,7 @@ Bugfixes
-----------
* Fix users resetting their own password [see `PR #195 <http://www.github.com/SeitaBV/flexmeasures/pull/195>`_]
* Fix scheduling for heterogeneous settings, for instance, involving sensors with different timezones and/or resolutions [see `PR #207 <http://www.github.com/SeitaBV/flexmeasures/pull/207>`_]
* Fix ``sensors/<id>/chart`` view [see `PR #223 <http://www.github.com/SeitaBV/flexmeasures/pull/223>`_]

Infrastructure / Support
----------------------
Expand Down
28 changes: 13 additions & 15 deletions flexmeasures/ui/views/sensors.py
@@ -1,7 +1,9 @@
import json

from altair.utils.html import spec_to_html
from flask import current_app
from flask_classful import FlaskView, route
from flask_security import login_required, roles_required
from flask_security import login_required
from marshmallow import fields
from webargs.flaskparser import use_kwargs

Expand All @@ -20,7 +22,6 @@ class SensorUI(FlaskView):
route_base = "/sensors"

@login_required
@roles_required("admin") # todo: remove after we check for sensor ownership
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
@route("/<id>/chart/")
@use_kwargs(
{
Expand All @@ -34,23 +35,20 @@ class SensorUI(FlaskView):
)
def get_chart(self, id, **kwargs):
"""GET from /sensors/<id>/chart"""
chart_specs = SensorAPI().get_chart(
id, include_data=True, as_html=True, **kwargs
)
chart_specs = SensorAPI().get_chart(id, include_data=True, **kwargs)
return spec_to_html(
chart_specs,
"vega-lite",
vega_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS").vega,
vegaembed_version=current_app.config.get(
"FLEXMEASURES_JS_VERSIONS"
).vegaembed,
vegalite_version=current_app.config.get(
"FLEXMEASURES_JS_VERSIONS"
).vegalite,
json.loads(chart_specs),
mode="vega-lite",
vega_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")["vega"],
vegaembed_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")[
"vegaembed"
],
vegalite_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")[
"vegalite"
],
)

@login_required
@roles_required("admin") # todo: remove after we check for sensor ownership
def get(self, id: int):
"""GET from /sensors/<id>"""
return render_flexmeasures_template(
Expand Down