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 %}