From f54c9cfbb785b5239e0cccda98c3caea3c9ff54e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 30 Jan 2024 11:07:28 +0000 Subject: [PATCH] Switch to using cards for trip pay layout Closes: #125 --- agenda/trip.py | 4 ++++ agenda/types.py | 4 ++-- templates/trip_page.html | 52 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index d5f9adc..fe2be90 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -3,6 +3,7 @@ import os from datetime import date import flask +import yaml from agenda import travel from agenda.types import StrDict, Trip @@ -44,12 +45,15 @@ def load_flights() -> list[StrDict]: """Load flights.""" data_dir = flask.current_app.config["PERSONAL_DATA"] flights = load_travel("flight") + airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml"))) airports = travel.parse_yaml("airports", data_dir) for flight in flights: if flight["from"] in airports: flight["from_airport"] = airports[flight["from"]] if flight["to"] in airports: flight["to_airport"] = airports[flight["to"]] + if "airline" in flight: + flight["airline_name"] = airlines.get(flight["airline"], "[unknown]") return flights diff --git a/agenda/types.py b/agenda/types.py index d1668c5..608a6fb 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -106,14 +106,14 @@ class Trip: def countries_str(self) -> str: """List of countries visited on this trip.""" return format_list_with_ampersand( - [f"{c.flag} {c.name}" for c in self.countries] + [f"{c.name} {c.flag}" for c in self.countries] ) @property def locations_str(self) -> str: """List of countries visited on this trip.""" return format_list_with_ampersand( - [f"{location} {c.flag}" for location, c in self.locations()] + [f"{location} ({c.name}) {c.flag}" for location, c in self.locations()] ) @property diff --git a/templates/trip_page.html b/templates/trip_page.html index 03e86d1..b002643 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -2,7 +2,7 @@ {% block title %}{{ trip.title }} ({{ display_date(trip.start) }}){% endblock %} -{% from "macros.html" import trip_link, display_date_no_year, display_date, conference_row, accommodation_row, flight_row, train_row with context %} +{% from "macros.html" import trip_link, display_datetime, display_date_no_year, display_date, conference_row, accommodation_row, flight_row, train_row with context %} {% set row = { "flight": flight_row, "train": train_row } %} @@ -78,7 +78,8 @@

-
Countries: {{ trip.countries_str }}
+ {#
Countries: {{ trip.countries_str }}
#} +
Locations: {{ trip.locations_str }}
{% set delta = human_readable_delta(trip.start) %} {% if delta %} @@ -176,9 +177,50 @@
{% endfor %} -
- {% for item in trip.travel %} {{ row[item.type](item) }} {% endfor %} -
+ {% for item in trip.travel %} +
+
+
+ {% if item.type == "flight" %} + ✈️ + {{ item.from_airport.name }} ({{ item.from_airport.iata}}) + → + {{ item.to_airport.name }} ({{item.to_airport.iata}}) + {% elif item.type == "train" %} + 🚆 + {{ item.from }} + → + {{ item.to }} + {% endif %} +
+

+ {% if item.type == "flight" %} +

+ {{ item.airline_name }} ({{ item.airline }}) + ✨ + {{ display_datetime(item.depart) }} + → + {{ item.arrive.strftime("%H:%M %z") }} + ✨ + {{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins + ✨ + {{ item.airline }}{{ item.flight_number }} +
+ {% elif item.type == "train" %} +
+ {{ display_datetime(item.depart) }} + → + {{ item.arrive.strftime("%H:%M %z") }} + {% if item.class %} + {{ item.class }} + {% endif %} + {{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins +
+ {% endif %} +

+
+
+ {% endfor %}

Holidays