diff --git a/agenda/types.py b/agenda/types.py index ed59d86..d150db6 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -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: diff --git a/templates/trip_list.html b/templates/trip_list.html index 58bc5a9..7ab7d9e 100644 --- a/templates/trip_list.html +++ b/templates/trip_list.html @@ -52,6 +52,7 @@

{{ heading }}

{{ items | count }} trips

{% for trip in items %} + {% set total_distance = trip.total_distance() %} {% set end = trip.end %}

@@ -63,6 +64,11 @@ {% else %}
Start: {{ display_date_no_year(trip.start) }} (end date missing)
{% endif %} + {% if total_distance %} +
Total distance: + {{ "{:,.0f} km / {:,.0f} miles".format(total_distance, total_distance / 1.60934) }} +
+ {% endif %}
{% for conf in trip.conferences %} {{ conference_row(conf, "going") }}