🇬🇧 Hide UK flags for all UK trips with show_flags logic 🏴

Implement show_flags property to conditionally display country flags for international trips. Remove unnecessary UK flags on purely UK-based trips. Closes: #183

🔧 Updated templates to use show_flags property.
📝 Adjusted map and trip details to reflect flag changes.
This commit is contained in:
Edward Betts 2024-10-19 19:43:48 +01:00
parent 9ad2ba9462
commit 3c0694de19
4 changed files with 28 additions and 36 deletions

View file

@ -2,6 +2,7 @@
import collections
import datetime
import functools
import typing
from collections import defaultdict
from dataclasses import dataclass, field
@ -167,6 +168,11 @@ class Trip:
# Don't include GB in countries visited unless entire trip was GB based
return [c for c in items if c.alpha_2 != "GB"] or items
@functools.cached_property
def show_flags(self) -> bool:
"""Show flags for international trips."""
return len(self.countries) != 1 or self.countries[0].name != "United Kingdom"
@property
def countries_str(self) -> str:
"""List of countries visited on this trip."""
@ -178,7 +184,10 @@ class Trip:
def locations_str(self) -> str:
"""List of countries visited on this trip."""
return format_list_with_ampersand(
[f"{location} ({c.name}) {c.flag}" for location, c in self.locations()]
[
f"{location} ({c.name})" + (f" {c.flag}" if self.show_flags else "")
for location, c in self.locations()
]
)
@property

View file

@ -13,7 +13,7 @@
<a href="{{ url_for("trip_page", start=trip.start.isoformat()) }}">{{ trip.title }}</a>
{% endmacro %}
{% macro conference_row(item, badge) %}
{% macro conference_row(item, badge, show_flags=True) %}
{% set country = get_country(item.country) if item.country else None %}
<div class="grid-item text-end">{{ item.start.strftime("%a, %d %b %Y") }}</div>
<div class="grid-item text-end">{{ item.end.strftime("%a, %d %b") }}</div>
@ -50,7 +50,7 @@
<div class="grid-item text-end">{{ display_date(item.cfp_end) if item.cfp_end else "" }}</div>
<div class="grid-item">
{% if country %}
{{ country.flag }} {{ country.name }}
{% if show_flags %}{{ country.flag }}{% endif %} {{ country.name }}
{% elif item.online %}
💻 Online
{% else %}
@ -61,7 +61,7 @@
</div>
{% endmacro %}
{% macro accommodation_row(item, badge) %}
{% macro accommodation_row(item, badge, show_flags=True) %}
{% set country = get_country(item.country) %}
{% set nights = (item.to.date() - item.from.date()).days %}
@ -72,7 +72,7 @@
<div class="grid-item">{{ item.location }}</div>
<div class="grid-item">
{% if country %}
{{ country.flag }} {{ country.name }}
{% if show_flags %}{{ country.flag }}{% endif %} {{ country.name }}
{% else %}
<span class="text-bg-danger p-2">
country code <strong>{{ item.country }}</strong> not found
@ -96,7 +96,7 @@
</div>
{% endmacro %}
{% macro flight_booking_row(booking) %}
{% macro flight_booking_row(booking, show_flags=True) %}
<div class="grid-item">
{% if g.user.is_authenticated %}
{{ booking.booking_reference or "reference missing" }}

View file

@ -25,25 +25,8 @@
top: 56px; /* Adjust to be below the navbar */
height: calc(100vh - 56px); /* Subtracting the height of the navbar */
}
.half-map {
height: 100vh;
}
.full-window-map {
position: fixed; /* Make the map fixed position */
top: 60px;
left: 0;
right: 0;
bottom: 0;
z-index: 9999; /* Make sure it sits on top */
}
#toggleMapSize {
position: fixed; /* Fixed position */
top: 70px; /* 10px from the top */
right: 10px; /* 10px from the right */
z-index: 10000; /* Higher than the map's z-index */
#map {
height: 100%;
}
@media (max-width: 767.98px) {
@ -64,13 +47,14 @@
</style>
{% endblock %}
{% macro flag(trip, flag) %}{% if trip.show_flags %}{{ flag }}{% endif %}{% endmacro %}
{% macro section(heading, item_list) %}
{% if item_list %}
{% set items = item_list | list %}
<div class="heading"><h2>{{ heading }}</h2></div>
<p><a href="{{ url_for("trip_stats") }}">Trip statistics</a></p>
<p>{{ items | count }} trips</p>
{% if item_list %}
<div>Total distance: {{ format_distance(total_distance) }}</div>
{% for transport_type, distance in distances_by_transport_type %}
@ -128,7 +112,7 @@
{% if e.element_type in accommodation_label %}
{% set c = get_country(e.detail.country) %}
<div>
{{ e.get_emoji() }} {{ e.title }} {{ c.flag }}
{{ e.get_emoji() }} {{ e.title }} {{ flag(trip, c.flag) }}
({{ accommodation_label[e.element_type] }} {{ display_time(e.start_time) }})
</div>
{% else %}
@ -136,11 +120,11 @@
{{ e.get_emoji() }}
{{ display_time(e.start_time) }}
&ndash;
{{ e.start_loc }} {{ e.start_country.flag }}
{{ e.start_loc }} {{ flag(trip, e.start_country.flag) }}
{{ display_time(e.end_time) }}
&ndash;
{{ e.end_loc }} {{ e.end_country.flag }}
{{ e.end_loc }} {{ flag(trip, e.end_country.flag) }}
{% if e.element_type == "flight" %}
{% set full_flight_number = e.detail.airline + e.detail.flight_number %}
{% set radarbox_url = "https://www.radarbox.com/data/flights/" + full_flight_number %}
@ -210,8 +194,7 @@
{% block content %}
<div class="container-fluid d-flex flex-column flex-md-row">
<div class="map-container col-12 col-md-6 order-1 order-md-2">
<button id="toggleMapSize" class="btn btn-primary mb-2">Toggle map size</button>
<div id="map" class="map half-map"></div>
<div id="map" class="map"></div>
</div>
<div class="text-content col-12 col-md-6 order-2 order-md-1 pe-3">
{{ section(heading, trips) }}

View file

@ -134,7 +134,7 @@
<strong>Venue:</strong> {{ item.venue }}
<strong>Location:</strong> {{ item.location }}
{% if country %}
{{ country.flag }}
{{ country.flag if trip.show_flags }}
{% elif item.online %}
💻 Online
{% else %}
@ -169,7 +169,7 @@
<strong>Address:</strong> {{ item.address }}
<strong>Location:</strong> {{ item.location }}
{% if country %}
{{ country.flag }}
{{ country.flag if trip.show_flags }}
{% else %}
<span class="text-bg-danger p-2">
country code <strong>{{ item.country }}</strong> not found
@ -210,7 +210,7 @@
Address: {{ item.address }}
| Location: {{ item.location }}
{% if country %}
{{ country.flag }}
{{ country.flag if trip.show_flags }}
{% else %}
<span class="text-bg-danger p-2">
country code <strong>{{ item.country }}</strong> not found
@ -297,7 +297,7 @@
{% else %}
<td></td>
{% endif %}
<td>{{ country.flag }} {{ country.name }}</td>
<td>{{ country.flag if trip.show_flags }} {{ country.name }}</td>
<td>{{ item.display_name }}</td>
</tr>
{% endfor %}