🇬🇧✨ 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:
parent
9ad2ba9462
commit
3c0694de19
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
import typing
|
import typing
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
@ -167,6 +168,11 @@ class Trip:
|
||||||
# Don't include GB in countries visited unless entire trip was GB based
|
# 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
|
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
|
@property
|
||||||
def countries_str(self) -> str:
|
def countries_str(self) -> str:
|
||||||
"""List of countries visited on this trip."""
|
"""List of countries visited on this trip."""
|
||||||
|
@ -178,7 +184,10 @@ class Trip:
|
||||||
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.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
|
@property
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<a href="{{ url_for("trip_page", start=trip.start.isoformat()) }}">{{ trip.title }}</a>
|
<a href="{{ url_for("trip_page", start=trip.start.isoformat()) }}">{{ trip.title }}</a>
|
||||||
{% endmacro %}
|
{% 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 %}
|
{% 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.start.strftime("%a, %d %b %Y") }}</div>
|
||||||
<div class="grid-item text-end">{{ item.end.strftime("%a, %d %b") }}</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 text-end">{{ display_date(item.cfp_end) if item.cfp_end else "" }}</div>
|
||||||
<div class="grid-item">
|
<div class="grid-item">
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }} {{ country.name }}
|
{% if show_flags %}{{ country.flag }}{% endif %} {{ country.name }}
|
||||||
{% elif item.online %}
|
{% elif item.online %}
|
||||||
💻 Online
|
💻 Online
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro accommodation_row(item, badge) %}
|
{% macro accommodation_row(item, badge, show_flags=True) %}
|
||||||
{% set country = get_country(item.country) %}
|
{% set country = get_country(item.country) %}
|
||||||
|
|
||||||
{% set nights = (item.to.date() - item.from.date()).days %}
|
{% set nights = (item.to.date() - item.from.date()).days %}
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
<div class="grid-item">{{ item.location }}</div>
|
<div class="grid-item">{{ item.location }}</div>
|
||||||
<div class="grid-item">
|
<div class="grid-item">
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }} {{ country.name }}
|
{% if show_flags %}{{ country.flag }}{% endif %} {{ country.name }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-bg-danger p-2">
|
<span class="text-bg-danger p-2">
|
||||||
country code <strong>{{ item.country }}</strong> not found
|
country code <strong>{{ item.country }}</strong> not found
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro flight_booking_row(booking) %}
|
{% macro flight_booking_row(booking, show_flags=True) %}
|
||||||
<div class="grid-item">
|
<div class="grid-item">
|
||||||
{% if g.user.is_authenticated %}
|
{% if g.user.is_authenticated %}
|
||||||
{{ booking.booking_reference or "reference missing" }}
|
{{ booking.booking_reference or "reference missing" }}
|
||||||
|
|
|
@ -25,25 +25,8 @@
|
||||||
top: 56px; /* Adjust to be below the navbar */
|
top: 56px; /* Adjust to be below the navbar */
|
||||||
height: calc(100vh - 56px); /* Subtracting the height of the navbar */
|
height: calc(100vh - 56px); /* Subtracting the height of the navbar */
|
||||||
}
|
}
|
||||||
|
#map {
|
||||||
.half-map {
|
height: 100%;
|
||||||
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 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
|
@ -64,13 +47,14 @@
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% macro flag(trip, flag) %}{% if trip.show_flags %}{{ flag }}{% endif %}{% endmacro %}
|
||||||
|
|
||||||
{% macro section(heading, item_list) %}
|
{% macro section(heading, item_list) %}
|
||||||
|
{% if item_list %}
|
||||||
{% set items = item_list | list %}
|
{% set items = item_list | list %}
|
||||||
<div class="heading"><h2>{{ heading }}</h2></div>
|
<div class="heading"><h2>{{ heading }}</h2></div>
|
||||||
<p><a href="{{ url_for("trip_stats") }}">Trip statistics</a></p>
|
|
||||||
<p>{{ items | count }} trips</p>
|
<p>{{ items | count }} trips</p>
|
||||||
|
|
||||||
{% if item_list %}
|
|
||||||
<div>Total distance: {{ format_distance(total_distance) }}</div>
|
<div>Total distance: {{ format_distance(total_distance) }}</div>
|
||||||
|
|
||||||
{% for transport_type, distance in distances_by_transport_type %}
|
{% for transport_type, distance in distances_by_transport_type %}
|
||||||
|
@ -128,7 +112,7 @@
|
||||||
{% if e.element_type in accommodation_label %}
|
{% if e.element_type in accommodation_label %}
|
||||||
{% set c = get_country(e.detail.country) %}
|
{% set c = get_country(e.detail.country) %}
|
||||||
<div>
|
<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) }})
|
({{ accommodation_label[e.element_type] }} {{ display_time(e.start_time) }})
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -136,11 +120,11 @@
|
||||||
{{ e.get_emoji() }}
|
{{ e.get_emoji() }}
|
||||||
{{ display_time(e.start_time) }}
|
{{ display_time(e.start_time) }}
|
||||||
–
|
–
|
||||||
{{ e.start_loc }} {{ e.start_country.flag }}
|
{{ e.start_loc }} {{ flag(trip, e.start_country.flag) }}
|
||||||
→
|
→
|
||||||
{{ display_time(e.end_time) }}
|
{{ display_time(e.end_time) }}
|
||||||
–
|
–
|
||||||
{{ e.end_loc }} {{ e.end_country.flag }}
|
{{ e.end_loc }} {{ flag(trip, e.end_country.flag) }}
|
||||||
{% if e.element_type == "flight" %}
|
{% if e.element_type == "flight" %}
|
||||||
{% set full_flight_number = e.detail.airline + e.detail.flight_number %}
|
{% set full_flight_number = e.detail.airline + e.detail.flight_number %}
|
||||||
{% set radarbox_url = "https://www.radarbox.com/data/flights/" + full_flight_number %}
|
{% set radarbox_url = "https://www.radarbox.com/data/flights/" + full_flight_number %}
|
||||||
|
@ -210,8 +194,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container-fluid d-flex flex-column flex-md-row">
|
<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">
|
<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"></div>
|
||||||
<div id="map" class="map half-map"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="text-content col-12 col-md-6 order-2 order-md-1 pe-3">
|
<div class="text-content col-12 col-md-6 order-2 order-md-1 pe-3">
|
||||||
{{ section(heading, trips) }}
|
{{ section(heading, trips) }}
|
||||||
|
|
|
@ -134,7 +134,7 @@
|
||||||
<strong>Venue:</strong> {{ item.venue }}
|
<strong>Venue:</strong> {{ item.venue }}
|
||||||
<strong>Location:</strong> {{ item.location }}
|
<strong>Location:</strong> {{ item.location }}
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }}
|
{{ country.flag if trip.show_flags }}
|
||||||
{% elif item.online %}
|
{% elif item.online %}
|
||||||
💻 Online
|
💻 Online
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -169,7 +169,7 @@
|
||||||
<strong>Address:</strong> {{ item.address }}
|
<strong>Address:</strong> {{ item.address }}
|
||||||
<strong>Location:</strong> {{ item.location }}
|
<strong>Location:</strong> {{ item.location }}
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }}
|
{{ country.flag if trip.show_flags }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-bg-danger p-2">
|
<span class="text-bg-danger p-2">
|
||||||
country code <strong>{{ item.country }}</strong> not found
|
country code <strong>{{ item.country }}</strong> not found
|
||||||
|
@ -210,7 +210,7 @@
|
||||||
Address: {{ item.address }}
|
Address: {{ item.address }}
|
||||||
| Location: {{ item.location }}
|
| Location: {{ item.location }}
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }}
|
{{ country.flag if trip.show_flags }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-bg-danger p-2">
|
<span class="text-bg-danger p-2">
|
||||||
country code <strong>{{ item.country }}</strong> not found
|
country code <strong>{{ item.country }}</strong> not found
|
||||||
|
@ -297,7 +297,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<td></td>
|
<td></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{ country.flag }} {{ country.name }}</td>
|
<td>{{ country.flag if trip.show_flags }} {{ country.name }}</td>
|
||||||
<td>{{ item.display_name }}</td>
|
<td>{{ item.display_name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue