Show trip total distance on trip list page

Closes: #142
This commit is contained in:
Edward Betts 2024-04-06 09:24:10 +02:00
parent fe4bde32ba
commit a7296c943b
2 changed files with 14 additions and 0 deletions

View file

@ -133,6 +133,14 @@ class Trip:
"""Countries flags for trip."""
return "".join(c.flag for c in self.countries)
def total_distance(self) -> float | None:
"""Total distance for trip."""
return (
sum(t["distance"] for t in self.travel)
if all(t.get("distance") for t in self.travel)
else None
)
@dataclass
class Holiday:

View file

@ -52,6 +52,7 @@
<div class="heading"><h2>{{ heading }}</h2></div>
<p>{{ items | count }} trips</p>
{% for trip in items %}
{% set total_distance = trip.total_distance() %}
{% set end = trip.end %}
<div class="border border-2 rounded mb-2 p-2">
<h3>
@ -63,6 +64,11 @@
{% else %}
<div>Start: {{ display_date_no_year(trip.start) }} (end date missing)</div>
{% endif %}
{% if total_distance %}
<div>Total distance:
{{ "{:,.0f} km / {:,.0f} miles".format(total_distance, total_distance / 1.60934) }}
</div>
{% endif %}
<div class="conferences">
{% for conf in trip.conferences %}
{{ conference_row(conf, "going") }}