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 @@
{{ items | count }} trips
{% for trip in items %} + {% set total_distance = trip.total_distance() %} {% set end = trip.end %}