Skip to content

Commit

Permalink
Merge 2b6898e into 763889d
Browse files Browse the repository at this point in the history
  • Loading branch information
Flix6x committed Dec 12, 2023
2 parents 763889d + 2b6898e commit 21d1830
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions flexmeasures/ui/crud/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask_wtf import FlaskForm
from flask_security import login_required, current_user
from wtforms import StringField, DecimalField, SelectField
from wtforms.validators import DataRequired
from wtforms.validators import DataRequired, optional
from flexmeasures.auth.policy import user_has_admin_access

from flexmeasures.data import db
Expand Down Expand Up @@ -40,11 +40,13 @@ class AssetForm(FlaskForm):
name = StringField("Name")
latitude = DecimalField(
"Latitude",
validators=[optional()],
places=None,
render_kw={"placeholder": "--Click the map or enter a latitude--"},
)
longitude = DecimalField(
"Longitude",
validators=[optional()],
places=None,
render_kw={"placeholder": "--Click the map or enter a longitude--"},
)
Expand All @@ -65,8 +67,10 @@ def validate_on_submit(self):
def to_json(self) -> dict:
"""turn form data into a JSON we can POST to our internal API"""
data = copy.copy(self.data)
data["longitude"] = float(data["longitude"])
data["latitude"] = float(data["latitude"])
if data.get("longitude") is not None:
data["longitude"] = float(data["longitude"])
if data.get("latitude") is not None:
data["latitude"] = float(data["latitude"])

if "csrf_token" in data:
del data["csrf_token"]
Expand Down

0 comments on commit 21d1830

Please sign in to comment.