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

View file

@ -77,6 +77,7 @@ class Trip:
accommodation: list[StrDict] = field(default_factory=list) accommodation: list[StrDict] = field(default_factory=list)
conferences: list[StrDict] = field(default_factory=list) conferences: list[StrDict] = field(default_factory=list)
events: 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 name: str | None = None
private: bool = False private: bool = False
@ -207,6 +208,11 @@ class Trip:
else None 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]]: def distances_by_transport_type(self) -> list[tuple[str, float]]:
"""Calculate the total distance travelled for each type of transport. """Calculate the total distance travelled for each type of transport.

View file

@ -114,9 +114,9 @@
</small> </small>
</h5> </h5>
<p class="card-text"> <p class="card-text">
Topic: {{ item.topic }} <strong>Topic:</strong> {{ item.topic }}
| Venue: {{ item.venue }} <strong>Venue:</strong> {{ item.venue }}
| Location: {{ item.location }} <strong>Location:</strong> {{ item.location }}
{% if country %} {% if country %}
{{ country.flag }} {{ country.flag }}
{% elif item.online %} {% elif item.online %}
@ -127,9 +127,9 @@
</span> </span>
{% endif %} {% endif %}
{% if item.free %} {% 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 %} {% 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 %} {% endif %}
</p> </p>
</div> </div>
@ -150,8 +150,8 @@
</small> </small>
</h5> </h5>
<p class="card-text"> <p class="card-text">
Address: {{ item.address }} <strong>Address:</strong> {{ item.address }}
| Location: {{ item.location }} <strong>Location:</strong> {{ item.location }}
{% if country %} {% if country %}
{{ country.flag }} {{ country.flag }}
{% else %} {% else %}
@ -160,13 +160,28 @@
</span> </span>
{% endif %} {% endif %}
{% if g.user.is_authenticated and item.price and item.currency %} {% 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 %} {% endif %}
</p> </p>
</div> </div>
</div> </div>
{% endfor %} {% 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 %} {% for item in trip.events %}
{% set country = get_country(item.country) if item.country else None %} {% set country = get_country(item.country) if item.country else None %}
<div class="card my-1"> <div class="card my-1">