Switch to using cards for trip pay layout

Closes: #125
This commit is contained in:
Edward Betts 2024-01-30 11:07:28 +00:00
parent f3304d0ffe
commit f54c9cfbb7
3 changed files with 53 additions and 7 deletions

View file

@ -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

View file

@ -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