fix: avoid error if asset has no geometry

This commit is contained in:
Lance Edgar 2026-03-21 15:24:36 -05:00
parent f0fa189bcd
commit 969497826d

View file

@ -372,21 +372,23 @@ class AssetMasterView(WuttaFarmMasterView):
# TODO: eventually sync GIS data, avoid this API call?
client = get_farmos_client_for_user(self.request)
result = client.asset.get_id(asset.asset_type, asset.farmos_uuid)
geometry = result["data"]["attributes"]["intrinsic_geometry"]
if geometry := result["data"]["attributes"]["intrinsic_geometry"]:
context["map_center"] = [geometry["lon"], geometry["lat"]]
context["map_center"] = [geometry["lon"], geometry["lat"]]
context["map_bounds"] = [
[geometry["left"], geometry["bottom"]],
[geometry["right"], geometry["top"]],
]
context["map_bounds"] = [
[geometry["left"], geometry["bottom"]],
[geometry["right"], geometry["top"]],
]
if match := re.match(
r"^POLYGON \(\((?P<points>[^\)]+)\)\)$", geometry["value"]
):
points = match.group("points").split(", ")
points = [[float(pt) for pt in pair.split(" ")] for pair in points]
context["map_polygon"] = [points]
if match := re.match(
r"^POLYGON \(\((?P<points>[^\)]+)\)\)$", geometry["value"]
):
points = match.group("points").split(", ")
points = [
[float(pt) for pt in pair.split(" ")] for pair in points
]
context["map_polygon"] = [points]
return context