trip: redesign itinerary display and add trip list macro
- Add render_trip_element macro to macros.html; use it in trip_item for the trip list page, giving a consistent one-line-per-element format with emoji, route, times, duration, operator, distance, and CO₂ - Redesign trip_page.html itinerary: day headers use date-only (no year), condense check-out to a single accent line, show time-only on transport cards, humanise duration (Xh Ym), km-only distance, add CO₂ for all transport modes, fix seat display for integer seat values - Fix UndefinedError on /trip/past caused by absent 'arrive' key (Jinja2 Undefined is truthy) and date-only depart/arrive fields (no .date()) - Improve mobile map layout: text column before map in HTML order, reduce mobile map heights, hide toggle button on mobile - Add trips.css with design system (Playfair Display / Source Sans 3 / JetBrains Mono, navy/gold/amber palette, card variants by type) - Add tests/test_trip_list_render.py covering the rendering edge cases Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b3975dad3a
commit
574b4feb1f
5 changed files with 935 additions and 338 deletions
|
|
@ -359,7 +359,7 @@ https://www.flightradar24.com/data/flights/{{ flight.airline_detail.iata | lower
|
|||
{% macro conference_list(trip) %}
|
||||
{% for item in trip.conferences %}
|
||||
{% set country = get_country(item.country) if item.country else None %}
|
||||
<div class="card my-1">
|
||||
<div class="trip-conference-card my-1">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
<a href="{{ item.url }}">{{ item.name }}</a>
|
||||
|
|
@ -394,34 +394,81 @@ https://www.flightradar24.com/data/flights/{{ flight.airline_detail.iata | lower
|
|||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_trip_element(e, trip) %}
|
||||
{% set item = e.detail %}
|
||||
{% if e.element_type == "check-in" %}
|
||||
{% set nights = (item.to.date() - item.from.date()).days %}
|
||||
<div class="trip-element">
|
||||
{{ e.get_emoji() }} <strong>{{ item.name }}</strong>
|
||||
{% if item.operator and item.operator != item.name %}<small class="text-muted">{{ item.operator }}</small>{% endif %}
|
||||
<small class="text-muted">({% if nights == 1 %}1 night{% else %}{{ nights }} nights{% endif %})</small>
|
||||
</div>
|
||||
{% elif e.element_type == "check-out" %}
|
||||
<div class="trip-checkout">
|
||||
{{ e.get_emoji() }} Check out: {{ item.name }}
|
||||
{% if item.operator and item.operator != item.name %}<span class="text-muted small">{{ item.operator }}</span>{% endif %}
|
||||
</div>
|
||||
{% elif e.element_type != "conference" %}
|
||||
{# Transport: flight, train, ferry, coach, bus #}
|
||||
{% set has_arrive = item.arrive is defined and item.arrive %}
|
||||
{# item.depart may be a date (no .date() method) or a datetime (has .date()) #}
|
||||
{% set has_time = item.depart is defined and item.depart and item.depart.hour is defined %}
|
||||
{% set depart_date = item.depart.date() if has_time else item.depart %}
|
||||
{% set arrive_date = item.arrive.date() if (has_arrive and item.arrive.hour is defined) else item.arrive %}
|
||||
{% set is_overnight = has_arrive and depart_date != arrive_date %}
|
||||
{% set dur_mins = ((item.arrive - item.depart).total_seconds() // 60) | int if (has_time and has_arrive) else none %}
|
||||
<div class="trip-element">
|
||||
{% if is_overnight %}🌙{% else %}{{ e.get_emoji() }}{% endif %}
|
||||
{{ e.start_loc }} → {{ e.end_loc }}
|
||||
{% if has_time %}
|
||||
· {{ item.depart.strftime("%H:%M") }}{% if has_arrive and item.arrive.hour is defined %} → {{ item.arrive.strftime("%H:%M") }}{% if is_overnight %} <span class="text-muted small">+1 day</span>{% endif %}{% endif %}
|
||||
{% endif %}
|
||||
{% if dur_mins %}
|
||||
{%- set h = dur_mins // 60 %}{%- set m = dur_mins % 60 %}
|
||||
<span class="text-muted">🕒{% if h %}{{ h }}h {% endif %}{% if m %}{{ m }}m{% endif %}</span>
|
||||
{% endif %}
|
||||
{% if e.element_type == "flight" %}
|
||||
<small class="text-muted">· {{ item.airline_name }} {{ item.airline_code }}{{ item.flight_number }}</small>
|
||||
{% elif item.operator %}
|
||||
<small class="text-muted">· {{ item.operator }}</small>
|
||||
{% endif %}
|
||||
{% if item.distance %}
|
||||
<span class="text-muted small">· {{ "{:,.0f} km".format(item.distance) }}</span>
|
||||
{% endif %}
|
||||
{% if item.co2_kg is defined and item.co2_kg is not none %}
|
||||
<span class="text-muted small">CO₂ {{ "{:,.1f}".format(item.co2_kg) }} kg</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro trip_item(trip) %}
|
||||
{% set distances_by_transport_type = trip.distances_by_transport_type() %}
|
||||
{% set total_distance = trip.total_distance() %}
|
||||
{% set total_co2_kg = trip.total_co2_kg() %}
|
||||
{% set end = trip.end %}
|
||||
<div class="border border-2 rounded mb-2 p-2">
|
||||
<h3>
|
||||
{% set trip_end = end or trip.start %}
|
||||
{% set is_current = trip.start <= today and trip_end >= today %}
|
||||
<div class="trip-card{% if is_current %} trip-current{% endif %}">
|
||||
<h3 class="trip-name">
|
||||
{{ trip_link(trip) }}
|
||||
<small class="text-muted">({{ display_date(trip.start) }})</small></h3>
|
||||
<small>({{ display_date(trip.start) }})</small></h3>
|
||||
{% set school_holidays = trip_school_holiday_map.get(trip.start.isoformat(), []) if trip_school_holiday_map is defined else [] %}
|
||||
{% if school_holidays %}
|
||||
<div>
|
||||
<div class="school-holiday-info">
|
||||
<span class="badge bg-warning text-dark">UK school holiday</span>
|
||||
{% for item in school_holidays %}
|
||||
<span class="text-muted">{{ item.title }} ({{ display_date_no_year(item.as_date) }} to {{ display_date_no_year(item.end_as_date) }})</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<ul class="list-unstyled">
|
||||
<ul class="list-unstyled trip-countries">
|
||||
{% for c in trip.countries %}
|
||||
<li>
|
||||
{{ c.name }}
|
||||
{{ c.flag }}
|
||||
</li>
|
||||
<li>{{ c.flag }} {{ c.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if end %}
|
||||
<div>Dates: {{ display_date_no_year(trip.start) }} to {{ display_date_no_year(end) }}
|
||||
<div class="trip-dates">Dates: {{ display_date_no_year(trip.start) }} to {{ display_date_no_year(end) }}
|
||||
{% if g.user.is_authenticated and trip.start <= today %}
|
||||
<a href="https://photos.4angle.com/search?query=%7B%22takenAfter%22%3A%22{{trip.start}}T00%3A00%3A00.000Z%22%2C%22takenBefore%22%3A%22{{end}}T23%3A59%3A59.999Z%22%7D">photos</a>
|
||||
{% endif %}
|
||||
|
|
@ -429,36 +476,25 @@ https://www.flightradar24.com/data/flights/{{ flight.airline_detail.iata | lower
|
|||
{% else %}
|
||||
<div>Start: {{ display_date_no_year(trip.start) }} (end date missing)</div>
|
||||
{% endif %}
|
||||
<div class="trip-stats">
|
||||
{% if total_distance %}
|
||||
<div>
|
||||
Total distance:
|
||||
{{ format_distance(total_distance) }}
|
||||
</div>
|
||||
<span class="trip-stat">{{ format_distance(total_distance) }}</span>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if distances_by_transport_type %}
|
||||
{% for transport_type, distance in distances_by_transport_type %}
|
||||
<div>
|
||||
{{ transport_type | title }}
|
||||
distance: {{format_distance(distance) }}
|
||||
</div>
|
||||
<span class="trip-stat">{{ transport_type | title }}: {{format_distance(distance) }}</span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if total_co2_kg %}
|
||||
<div>Total CO₂: {{ "{:,.1f}".format(total_co2_kg) }} kg</div>
|
||||
<span class="trip-stat">CO₂ {{ "{:,.1f}".format(total_co2_kg) }} kg</span>
|
||||
{% endif %}
|
||||
|
||||
{% set co2_by_transport = trip.co2_by_transport_type() %}
|
||||
{% if co2_by_transport %}
|
||||
{% for transport_type, co2_kg in co2_by_transport %}
|
||||
<div>
|
||||
{{ transport_type | title }}
|
||||
CO₂: {{ "{:,.1f}".format(co2_kg) }} kg
|
||||
</div>
|
||||
<span class="trip-stat">{{ transport_type | title }} CO₂ {{ "{:,.1f}".format(co2_kg) }} kg</span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if trip.schengen_compliance %}
|
||||
<div>
|
||||
|
|
@ -477,62 +513,21 @@ https://www.flightradar24.com/data/flights/{{ flight.airline_detail.iata | lower
|
|||
{% set trip_weather = trip_weather_map.get(trip.start.isoformat(), {}) if trip_weather_map is defined else {} %}
|
||||
{% for day, elements in trip.elements_grouped_by_day() %}
|
||||
{% set weather = trip_weather.get(day.isoformat()) %}
|
||||
<h4>{{ display_date_no_year(day) }}
|
||||
<h4 class="trip-day-header">{{ display_date_no_year(day) }}
|
||||
{% if weather %}
|
||||
<small class="text-muted">
|
||||
<img src="https://openweathermap.org/img/wn/{{ weather.icon }}.png" alt="{{ weather.status }}" title="{{ weather.detailed_status }}" width="25" height="25">
|
||||
{{ weather.temp_min }}–{{ weather.temp_max }}°C {{ weather.detailed_status }}
|
||||
</small>
|
||||
{% endif %}
|
||||
{% if g.user.is_authenticated and day <= today %}
|
||||
<span class="lead">
|
||||
<a href="https://photos.4angle.com/search?query=%7B%22takenAfter%22%3A%22{{day}}T00%3A00%3A00.000Z%22%2C%22takenBefore%22%3A%22{{day}}T23%3A59%3A59.999Z%22%7D">photos</a>
|
||||
<span class="trip-weather-inline">
|
||||
<img src="https://openweathermap.org/img/wn/{{ weather.icon }}.png" alt="{{ weather.status }}" title="{{ weather.detailed_status }}" width="18" height="18">
|
||||
{{ weather.temp_min }}–{{ weather.temp_max }}°C
|
||||
<span class="fw-normal fst-italic">{{ weather.detailed_status }}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</h4>
|
||||
{% set accommodation_label = {"check-in": "check-in from", "check-out": "check-out by"} %}
|
||||
{% for e in elements %}
|
||||
{% if e.element_type in accommodation_label %}
|
||||
{% set c = get_country(e.detail.country) %}
|
||||
<div>
|
||||
{{ e.get_emoji() }} {{ e.title }} {{ flag(trip, c.flag) }}
|
||||
({{ accommodation_label[e.element_type] }} {{ display_time(e.start_time) }})
|
||||
</div>
|
||||
{% else %}
|
||||
<div>
|
||||
{{ e.get_emoji() }}
|
||||
{{ display_time(e.start_time) }}
|
||||
–
|
||||
{{ e.start_loc }} {{ flag(trip, e.start_country.flag) }}
|
||||
→
|
||||
{{ display_time(e.end_time) }}
|
||||
–
|
||||
{{ e.end_loc }} {{ flag(trip, e.end_country.flag) }}
|
||||
{% if e.element_type == "flight" %}
|
||||
{% set flight = e.detail %}
|
||||
{% set full_flight_number = flight.airline_code + flight.flight_number %}
|
||||
{% set radarbox_url = "https://www.radarbox.com/data/flights/" + full_flight_number %}
|
||||
<span class="text-nowrap"><strong>airline:</strong> {{ flight.airline_name }}</span>
|
||||
<span class="text-nowrap"><strong>flight number:</strong> {{ full_flight_number }}</span>
|
||||
{% if flight.duration %}
|
||||
<span class="text-nowrap"><strong>duration:</strong> {{ flight.duration }}</span>
|
||||
{% endif %}
|
||||
{# <pre>{{ flight | pprint }}</pre> #}
|
||||
{% if flight.co2_kg is defined and flight.co2_kg is not none %}
|
||||
<span class="text-nowrap"><strong>CO₂:</strong> {{ "{:,.1f}".format(flight.co2_kg) }} kg</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if e.detail.distance %}
|
||||
<span class="text-nowrap"><strong>distance:</strong> {{ format_distance(e.detail.distance) }}</span>
|
||||
{% endif %}
|
||||
{% if e.element_type == "flight" %}
|
||||
<a href="{{ flightradar24_url(flight) }}">flightradar24</a>
|
||||
| <a href="https://uk.flightaware.com/live/flight/{{ full_flight_number }}">FlightAware</a>
|
||||
| <a href="{{ radarbox_url }}">radarbox</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if g.user.is_authenticated and day <= today %}
|
||||
<a class="ms-2 small fw-normal" href="https://photos.4angle.com/search?query=%7B%22takenAfter%22%3A%22{{day}}T00%3A00%3A00.000Z%22%2C%22takenBefore%22%3A%22{{day}}T23%3A59%3A59.999Z%22%7D">photos</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</h4>
|
||||
{% for e in elements %}
|
||||
{{ render_trip_element(e, trip) }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue