Move flag display to trip list template
This commit is contained in:
parent
75242c2952
commit
537a84ff67
|
@ -45,6 +45,8 @@ class TripElement:
|
|||
end_time: DateOrDateTime | None = None
|
||||
start_loc: str | None = None
|
||||
end_loc: str | None = None
|
||||
start_country: Country | None = None
|
||||
end_country: Country | None = None
|
||||
|
||||
def get_emoji(self) -> str | None:
|
||||
"""Emoji for trip element."""
|
||||
|
@ -63,9 +65,7 @@ class TripElement:
|
|||
def airport_label(airport: StrDict) -> str:
|
||||
"""Airport label: name and iata."""
|
||||
name = airport.get("alt_name") or airport["city"]
|
||||
country = agenda.get_country(airport["country"])
|
||||
assert country and country.flag
|
||||
return f"{name} ({airport['iata']}) {country.flag}"
|
||||
return f"{name} ({airport['iata']})"
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -234,6 +234,9 @@ class Trip:
|
|||
+ f"{airport_label(item['to_airport'])}"
|
||||
)
|
||||
|
||||
from_country = agenda.get_country(item["from_airport"]["country"])
|
||||
to_country = agenda.get_country(item["to_airport"]["country"])
|
||||
|
||||
elements.append(
|
||||
TripElement(
|
||||
start_time=item["depart"],
|
||||
|
@ -243,6 +246,8 @@ class Trip:
|
|||
element_type="flight",
|
||||
start_loc=airport_label(item["from_airport"]),
|
||||
end_loc=airport_label(item["to_airport"]),
|
||||
start_country=from_country,
|
||||
end_country=to_country,
|
||||
)
|
||||
)
|
||||
if item["type"] == "train":
|
||||
|
@ -251,9 +256,7 @@ class Trip:
|
|||
to_country = agenda.get_country(leg["to_station"]["country"])
|
||||
|
||||
assert from_country and to_country
|
||||
from_flag = from_country.flag
|
||||
to_flag = to_country.flag
|
||||
name = f"{leg['from']} {from_flag} → {leg['to']} {to_flag}"
|
||||
name = f"{leg['from']} → {leg['to']}"
|
||||
elements.append(
|
||||
TripElement(
|
||||
start_time=leg["depart"],
|
||||
|
@ -261,19 +264,17 @@ class Trip:
|
|||
title=name,
|
||||
detail=leg,
|
||||
element_type="train",
|
||||
start_loc=f"{leg['from']} {from_flag}",
|
||||
end_loc=f"{leg['to']} {to_flag}",
|
||||
start_loc=leg["from"],
|
||||
end_loc=leg["to"],
|
||||
start_country=from_country,
|
||||
end_country=to_country,
|
||||
)
|
||||
)
|
||||
if item["type"] == "ferry":
|
||||
from_country = agenda.get_country(item["from_terminal"]["country"])
|
||||
to_country = agenda.get_country(item["to_terminal"]["country"])
|
||||
|
||||
assert from_country and to_country
|
||||
from_flag = from_country.flag
|
||||
to_flag = to_country.flag
|
||||
|
||||
name = f"{item['from']} {from_flag} → {item['to']} {to_flag}"
|
||||
name = f"{item['from']} → {item['to']}"
|
||||
elements.append(
|
||||
TripElement(
|
||||
start_time=item["depart"],
|
||||
|
@ -281,8 +282,10 @@ class Trip:
|
|||
title=name,
|
||||
detail=item,
|
||||
element_type="ferry",
|
||||
start_loc=f"{item['from']} {from_flag}",
|
||||
end_loc=f"{item['to']} {to_flag}",
|
||||
start_loc=item["from"],
|
||||
end_loc=item["to"],
|
||||
start_country=from_country,
|
||||
end_country=to_country,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -118,11 +118,11 @@
|
|||
{{ e.get_emoji() }}
|
||||
{{ display_time(e.start_time) }}
|
||||
–
|
||||
{{ e.start_loc }}
|
||||
{{ e.start_loc }} {{ e.start_country.flag }}
|
||||
→
|
||||
{{ display_time(e.end_time) }}
|
||||
–
|
||||
{{ e.end_loc }}
|
||||
{{ e.end_loc }} {{ e.end_country.flag }}
|
||||
{% if e.element_type == "flight" %}
|
||||
<span class="text-nowrap"><strong>airline:</strong> {{ e.detail.airline_name }}</span>
|
||||
<span class="text-nowrap"><strong>flight number:</strong> {{ e.detail.airline }}{{ e.detail.flight_number }}</span>
|
||||
|
|
Loading…
Reference in a new issue