Skip to content

Commit

Permalink
Add a link to village locations to /villages
Browse files Browse the repository at this point in the history
I have had to answer questions about where villages are too many times, and we
can't search map.emfcamp.org.
  • Loading branch information
lukegb committed May 30, 2024
1 parent c7e7f95 commit f1649c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/villages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/<int:year>/<int:village_id>/edit", methods=["GET", "POST"])
Expand Down
14 changes: 14 additions & 0 deletions models/village.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions templates/villages/villages.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h3>List of Villages</h3>
<tr>
<th>Name</th>
<th>Description</th>
{% if any_village_located %}<th></th>{% endif %}
</tr>
</thead>
<tbody>
Expand All @@ -28,6 +29,14 @@ <h3>List of Villages</h3>
<td>{{village.name}}</td>
{% endif %}
<td style="overflow-wrap: anywhere">{{village.description}}</td>
{% if any_village_located %}
<td style="width: 1px; white-space: nowrap;">
{% if village.map_link %}
<a href="{{ village.map_link }}">📍&nbsp;Map</a>
{% endif %}
</td>
{% endif %}

</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit f1649c4

Please sign in to comment.