parent
f3304d0ffe
commit
f54c9cfbb7
|
@ -3,6 +3,7 @@ import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
import yaml
|
||||||
|
|
||||||
from agenda import travel
|
from agenda import travel
|
||||||
from agenda.types import StrDict, Trip
|
from agenda.types import StrDict, Trip
|
||||||
|
@ -44,12 +45,15 @@ def load_flights() -> list[StrDict]:
|
||||||
"""Load flights."""
|
"""Load flights."""
|
||||||
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
||||||
flights = load_travel("flight")
|
flights = load_travel("flight")
|
||||||
|
airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml")))
|
||||||
airports = travel.parse_yaml("airports", data_dir)
|
airports = travel.parse_yaml("airports", data_dir)
|
||||||
for flight in flights:
|
for flight in flights:
|
||||||
if flight["from"] in airports:
|
if flight["from"] in airports:
|
||||||
flight["from_airport"] = airports[flight["from"]]
|
flight["from_airport"] = airports[flight["from"]]
|
||||||
if flight["to"] in airports:
|
if flight["to"] in airports:
|
||||||
flight["to_airport"] = airports[flight["to"]]
|
flight["to_airport"] = airports[flight["to"]]
|
||||||
|
if "airline" in flight:
|
||||||
|
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
||||||
return flights
|
return flights
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,14 +106,14 @@ class Trip:
|
||||||
def countries_str(self) -> str:
|
def countries_str(self) -> str:
|
||||||
"""List of countries visited on this trip."""
|
"""List of countries visited on this trip."""
|
||||||
return format_list_with_ampersand(
|
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
|
@property
|
||||||
def locations_str(self) -> str:
|
def locations_str(self) -> str:
|
||||||
"""List of countries visited on this trip."""
|
"""List of countries visited on this trip."""
|
||||||
return format_list_with_ampersand(
|
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
|
@property
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block title %}{{ trip.title }} ({{ display_date(trip.start) }}){% endblock %}
|
{% 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 } %}
|
{% set row = { "flight": flight_row, "train": train_row } %}
|
||||||
|
|
||||||
|
@ -78,7 +78,8 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div>Countries: {{ trip.countries_str }}</div>
|
{# <div>Countries: {{ trip.countries_str }}</div> #}
|
||||||
|
<div>Locations: {{ trip.locations_str }}</div>
|
||||||
|
|
||||||
{% set delta = human_readable_delta(trip.start) %}
|
{% set delta = human_readable_delta(trip.start) %}
|
||||||
{% if delta %}
|
{% if delta %}
|
||||||
|
@ -176,9 +177,50 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<div class="travel">
|
{% for item in trip.travel %}
|
||||||
{% for item in trip.travel %} {{ row[item.type](item) }} {% endfor %}
|
<div class="card my-1">
|
||||||
</div>
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">
|
||||||
|
{% 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 %}
|
||||||
|
</h5>
|
||||||
|
<p class="card-text">
|
||||||
|
{% if item.type == "flight" %}
|
||||||
|
<div>
|
||||||
|
<span>{{ item.airline_name }} ({{ item.airline }})</span>
|
||||||
|
✨
|
||||||
|
{{ display_datetime(item.depart) }}
|
||||||
|
→
|
||||||
|
{{ item.arrive.strftime("%H:%M %z") }}
|
||||||
|
✨
|
||||||
|
<span>{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins</span>
|
||||||
|
✨
|
||||||
|
<span>{{ item.airline }}{{ item.flight_number }}</span>
|
||||||
|
</div>
|
||||||
|
{% elif item.type == "train" %}
|
||||||
|
<div>
|
||||||
|
{{ display_datetime(item.depart) }}
|
||||||
|
→
|
||||||
|
{{ item.arrive.strftime("%H:%M %z") }}
|
||||||
|
{% if item.class %}
|
||||||
|
<span class="badge bg-info text-nowrap">{{ item.class }}</span>
|
||||||
|
{% endif %}
|
||||||
|
<span>{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<h4>Holidays</h4>
|
<h4>Holidays</h4>
|
||||||
|
|
Loading…
Reference in a new issue