Skip to content

Commit

Permalink
Using wrong format in asset editing leads to unhelpful error message (#…
Browse files Browse the repository at this point in the history
…93)

asset edit form behaves better on form validation errors

Co-authored-by: nhoening <nhoening@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
3 people committed Apr 11, 2021
1 parent 6c6c232 commit ad6fa3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion documentation/changelog.rst
Expand Up @@ -3,13 +3,17 @@ FlexMeasures Changelog
**********************


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

New features
-----------
* Add sensors with CLI command [see `PR #83 <https://github.com/SeitaBV/flexmeasures/pull/83>`_]

Bugfixes
-----------
* Asset edit form displayed wrong error message. Also enabled the asset edit form to display the invalid user input back to the user [see `PR #93 <http://www.github.com/SeitaBV/flexmeasures/pull/93>`_]

Infrastructure / Support
----------------------
* Updated dependencies, including Flask-Security-Too [see `PR #82 <http://www.github.com/SeitaBV/flexmeasures/pull/82>`_]
Expand Down
15 changes: 13 additions & 2 deletions flexmeasures/ui/crud/assets.py
Expand Up @@ -278,11 +278,22 @@ def post(self, id: str):
else:
asset_form = with_options(AssetForm())
if not asset_form.validate_on_submit():
asset = Asset.query.get(id)
latest_measurement_time_str, asset_plot_html = get_latest_power_as_plot(
asset
)
# Display the form data, but set some extra data which the page wants to show.
asset_info = asset_form.data.copy()
asset_info["id"] = id
asset_info["owner_id"] = asset.owner_id
asset_info["entity_address"] = asset.entity_address
return render_flexmeasures_template(
"crud/asset_new.html",
"crud/asset.html",
asset_form=asset_form,
asset=asset_info,
msg="Cannot edit asset.",
map_center=get_center_location(db, user=current_user),
latest_measurement_time_str=latest_measurement_time_str,
asset_plot_html=asset_plot_html,
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)
patch_asset_response = InternalApi().patch(
Expand Down
12 changes: 6 additions & 6 deletions flexmeasures/ui/templates/crud/asset.html
Expand Up @@ -49,7 +49,7 @@
<h3>Edit asset {{ asset.display_name }}</h3>

<small>(Owned by <a href="/users/{{asset.owner_id}}">{{ asset.owner_id | username }}</a>)</small>

<div class="form-group">
{{ asset_form.display_name.label(class="col-sm-6 control-label") }}
<div class="col-sm-6">
Expand Down Expand Up @@ -198,7 +198,7 @@ <h3>Location</h3>

// create map
var assetMap = L
.map('mapid', { center: [{{ asset.latitude }}, {{ asset.longitude }}], zoom: 10})
.map('mapid', { center: [{{ asset.latitude | replace("None", 10) }}, {{ asset.longitude | replace("None", 10) }}], zoom: 10})
.on('popupopen', function () {
$(function () {
$('[data-toggle="tooltip"]').tooltip();
Expand All @@ -207,17 +207,17 @@ <h3>Location</h3>
addTileLayer(assetMap, '{{ mapboxAccessToken }}');

// create marker
var {{ asset.asset_type_name | parameterize }}_icon = new L.DivIcon({
var asset_icon = new L.DivIcon({
className: 'map-icon',
html: '<i class="icon-empty-marker center-icon supersize"></i><i class="overlay center-icon {{ asset.asset_type_name | asset_icon }}"></i>',
html: '<i class="icon-empty-marker center-icon supersize"></i><i class="overlay center-icon {{ asset.asset_type_name | default("info") | asset_icon }}"></i>',
iconSize: [100, 100], // size of the icon
iconAnchor: [50, 50], // point of the icon which will correspond to marker's location
popupAnchor: [0, -50] // point from which the popup should open relative to the iconAnchor
});
var marker = L
.marker(
[{{ asset.latitude }}, {{ asset.longitude }}],
{ icon: {{ asset.asset_type_name | parameterize }}_icon }
[{{ asset.latitude | replace("None", 10)}}, {{ asset.longitude | replace("None", 10) }}],
{ icon: asset_icon }
).addTo(assetMap);

assetMap.on('click', function (e) {
Expand Down

0 comments on commit ad6fa3f

Please sign in to comment.