From eee2a1df65ffc6d4b46c63322924b91fdd8719a3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 14 Mar 2026 22:38:30 -0500 Subject: [PATCH] feat: show basic map for "fixed" assets this is just to get our foot in the door so to speak. not sure yet how sophisticated this map needs to be etc. but thought it would be nice to at least show something..since the data is available --- .../web/templates/assets/master/view.mako | 71 ++++++++++++++++++- src/wuttafarm/web/templates/base.mako | 10 +++ src/wuttafarm/web/views/assets.py | 31 ++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/wuttafarm/web/templates/assets/master/view.mako b/src/wuttafarm/web/templates/assets/master/view.mako index dac5a1c..5b7b822 100644 --- a/src/wuttafarm/web/templates/assets/master/view.mako +++ b/src/wuttafarm/web/templates/assets/master/view.mako @@ -10,5 +10,74 @@ % endif - ${parent.page_content()} +
+ + ## main form +
+ ${parent.page_content()} +
+ + ## location map + % if map_polygon: +
+ % endif + +
+ + + +<%def name="modify_vue_vars()"> + ${parent.modify_vue_vars()} + % if map_polygon: + + % endif diff --git a/src/wuttafarm/web/templates/base.mako b/src/wuttafarm/web/templates/base.mako index b28b52f..caa5c67 100644 --- a/src/wuttafarm/web/templates/base.mako +++ b/src/wuttafarm/web/templates/base.mako @@ -1,6 +1,16 @@ <%inherit file="wuttaweb:templates/base.mako" /> <%namespace file="/wuttafarm-components.mako" import="make_wuttafarm_components" /> +<%def name="head_tags()"> + ${parent.head_tags()} + + ## TODO: this likely does not belong in the base template, and should be + ## included per template where actually needed. but this is easier for now. + + + + + <%def name="index_title_controls()"> ${parent.index_title_controls()} diff --git a/src/wuttafarm/web/views/assets.py b/src/wuttafarm/web/views/assets.py index 64f4dbc..35c3b21 100644 --- a/src/wuttafarm/web/views/assets.py +++ b/src/wuttafarm/web/views/assets.py @@ -23,6 +23,7 @@ Master view for Assets """ +import re from collections import OrderedDict from webhelpers2.html import tags @@ -359,6 +360,36 @@ class AssetMasterView(WuttaFarmMasterView): return buttons + def get_template_context(self, context): + context = super().get_template_context(context) + + if self.viewing: + asset = context["instance"] + + # add location geometry if applicable + if asset.is_fixed and asset.farmos_uuid and not self.app.is_standalone(): + + # 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"] + + context["map_center"] = [geometry["lon"], geometry["lat"]] + + context["map_bounds"] = [ + [geometry["left"], geometry["bottom"]], + [geometry["right"], geometry["top"]], + ] + + if match := re.match( + r"^POLYGON \(\((?P[^\)]+)\)\)$", 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 + def get_version_joins(self): """ We override this to declare the relationship between the