Show flight prices on individual trip pages

Closes: #153
This commit is contained in:
Edward Betts 2024-06-20 12:40:26 +01:00
parent 672948ed4d
commit f4557d14e8
3 changed files with 36 additions and 12 deletions

View file

@ -107,12 +107,12 @@ def load_flight_bookings(data_dir: str) -> list[StrDict]:
return bookings
def load_flights(data_dir: str) -> list[StrDict]:
def load_flights(flight_bookings: list[StrDict]) -> list[StrDict]:
"""Load flights."""
flights = []
for booking in load_flight_bookings(data_dir):
for booking in flight_bookings:
for flight in booking["flights"]:
for f in "type", "trip", "booking_reference":
for f in "type", "trip", "booking_reference", "price", "currency":
if f in booking:
flight[f] = booking[f]
flights.append(flight)
@ -133,14 +133,17 @@ def build_trip_list(
yaml_trip_lookup = {item["trip"]: item for item in yaml_trip_list}
flight_bookings = load_flight_bookings(data_dir)
travel_items = sorted(
load_flights(data_dir)
load_flights(flight_bookings)
+ load_trains(data_dir, route_distances=route_distances)
+ load_ferries(data_dir, route_distances=route_distances),
key=depart_datetime,
)
data = {
"flight_bookings": flight_bookings,
"travel": travel_items,
"accommodation": travel.parse_yaml("accommodation", data_dir),
"conferences": travel.parse_yaml("conferences", data_dir),

View file

@ -77,6 +77,7 @@ class Trip:
accommodation: list[StrDict] = field(default_factory=list)
conferences: list[StrDict] = field(default_factory=list)
events: list[StrDict] = field(default_factory=list)
flight_bookings: list[StrDict] = field(default_factory=list)
name: str | None = None
private: bool = False
@ -207,6 +208,11 @@ class Trip:
else None
)
@property
def flights(self) -> list[StrDict]:
"""Flights."""
return [item for item in self.travel if item["type"] == "flight"]
def distances_by_transport_type(self) -> list[tuple[str, float]]:
"""Calculate the total distance travelled for each type of transport.

View file

@ -114,9 +114,9 @@
</small>
</h5>
<p class="card-text">
Topic: {{ item.topic }}
| Venue: {{ item.venue }}
| Location: {{ item.location }}
<strong>Topic:</strong> {{ item.topic }}
<strong>Venue:</strong> {{ item.venue }}
<strong>Location:</strong> {{ item.location }}
{% if country %}
{{ country.flag }}
{% elif item.online %}
@ -127,9 +127,9 @@
</span>
{% endif %}
{% if item.free %}
| <span class="badge bg-success text-nowrap">free to attend</span>
<span class="badge bg-success text-nowrap">free to attend</span>
{% elif item.price and item.currency %}
| <span class="badge bg-info text-nowrap">price: {{ item.price }} {{ item.currency }}</span>
<span class="badge bg-info text-nowrap">price: {{ item.price }} {{ item.currency }}</span>
{% endif %}
</p>
</div>
@ -150,8 +150,8 @@
</small>
</h5>
<p class="card-text">
Address: {{ item.address }}
| Location: {{ item.location }}
<strong>Address:</strong> {{ item.address }}
<strong>Location:</strong> {{ item.location }}
{% if country %}
{{ country.flag }}
{% else %}
@ -160,13 +160,28 @@
</span>
{% endif %}
{% if g.user.is_authenticated and item.price and item.currency %}
| <span class="badge bg-info text-nowrap">price: {{ item.price }} {{ item.currency }}</span>
<span class="badge bg-info text-nowrap">price: {{ item.price }} {{ item.currency }}</span>
{% endif %}
</p>
</div>
</div>
{% endfor %}
{% if trip.flight_bookings %}
<h3>Flight bookings</h3>
{% for item in trip.flight_bookings %}
<div>
{{ item.flights | map(attribute="airline_name") | unique | join(" + ") }}
{% if g.user.is_authenticated and item.booking_reference %}
<strong>booking reference:</strong> {{ item.booking_reference }}
{% endif %}
{% if g.user.is_authenticated and item.price and item.currency %}
<span class="badge bg-info text-nowrap">price: {{ item.price }} {{ item.currency }}</span>
{% endif %}
</div>
{% endfor %}
{% endif %}
{% for item in trip.events %}
{% set country = get_country(item.country) if item.country else None %}
<div class="card my-1">