From 1d5a52e2570e357bb2dc4cfea773369feb2aa4a8 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Thu, 30 May 2024 18:07:19 +0000 Subject: [PATCH] Add a link to village locations to /villages I have had to answer questions about where villages are too many times, and we can't search map.emfcamp.org. --- apps/villages/views.py | 9 +++++++-- models/village.py | 14 ++++++++++++++ templates/villages/villages.html | 9 +++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/villages/views.py b/apps/villages/views.py index 7f86cdfd7..975dac64f 100644 --- a/apps/villages/views.py +++ b/apps/villages/views.py @@ -63,8 +63,13 @@ def main(year): if year != event_year(): abort(404) - villages = Village.query.all() - return render_template("villages/villages.html", villages=villages) + villages = list(Village.query.all()) + any_village_located = any(v.location is not None for v in villages) + return render_template( + "villages/villages.html", + villages=villages, + any_village_located=any_village_located, + ) @villages.route("///edit", methods=["GET", "POST"]) diff --git a/models/village.py b/models/village.py index 3e9f7fbbb..d408dd6e6 100644 --- a/models/village.py +++ b/models/village.py @@ -57,6 +57,20 @@ def __geo_interface__(self): "geometry": location.__geo_interface__, } + @property + def latlon(self): + if self.location: + loc = to_shape(self.location) + return (loc.y, loc.x) + return None + + @property + def map_link(self) -> Optional[str]: + latlon = self.latlon + if latlon: + return "https://map.emfcamp.org/#18.5/%s/%s/m=%s,%s" % (latlon[0], latlon[1], latlon[0], latlon[1]) + return None + # I'm not entirely sure why we create this index separately but this is how # it was done with the old MapObject stuff. diff --git a/templates/villages/villages.html b/templates/villages/villages.html index e4934782a..b8ec8c881 100644 --- a/templates/villages/villages.html +++ b/templates/villages/villages.html @@ -17,6 +17,7 @@

List of Villages

Name Description + {% if any_village_located %}{% endif %} @@ -28,6 +29,14 @@

List of Villages

{{village.name}} {% endif %} {{village.description}} + {% if any_village_located %} + + {% if village.map_link %} + 📍 Map + {% endif %} + + {% endif %} + {% endfor %}