diff --git a/agenda/types.py b/agenda/types.py index 50a2612..4642566 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -6,6 +6,7 @@ import typing from collections import Counter from dataclasses import dataclass, field +import emoji from pycountry.db import Country import agenda @@ -42,6 +43,18 @@ class TripElement: element_type: str detail: StrDict + def get_emoji(self) -> str | None: + """Emjoji for trip element.""" + if self.element_type in ("check-in", "check-out"): + return emoji.emojize(":hotel:", language="alias") + if self.element_type == "train": + return emoji.emojize(":train:", language="alias") + if self.element_type == "flight": + return emoji.emojize(":airplane:", language="alias") + if self.element_type == "ferry": + return emoji.emojize(":ferry:", language="alias") + return None + def airport_label(airport: StrDict) -> str: """Airport label: name and iata.""" @@ -259,6 +272,16 @@ class Trip: day = as_date(element.when) grouped_elements[day].append(element) + # Sort elements within each day + for day in grouped_elements: + grouped_elements[day].sort( + key=lambda e: ( + e.element_type == "check-in", # check-out elements last + e.element_type != "check-out", # check-in elements first + as_datetime(e.when), # then sort by time + ) + ) + # Convert the dictionary to a sorted list of tuples grouped_elements_list = sorted(grouped_elements.items()) diff --git a/requirements.txt b/requirements.txt index ba7a169..3ed2d57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ dateutil ephem flask requests +emoji diff --git a/templates/trip/list.html b/templates/trip/list.html index 7b2a3ab..662c020 100644 --- a/templates/trip/list.html +++ b/templates/trip/list.html @@ -82,13 +82,21 @@
{{ items | count }} trips
{% for trip in items %} + {% set distances_by_transport_type = trip.distances_by_transport_type() %} {% set total_distance = trip.total_distance() %} {% set end = trip.end %}+ Topic: {{ item.topic }} + | Venue: {{ item.venue }} + | Location: {{ item.location }} + {% if country %} + {{ country.flag }} + {% elif item.online %} + 💻 Online + {% else %} + + country code {{ item.country }} not found + + {% endif %} + {% if item.free %} + | free to attend + {% elif item.price and item.currency %} + | price: {{ item.price }} {{ item.currency }} + {% endif %} +
+- Topic: {{ item.topic }} - | Venue: {{ item.venue }} - | Location: {{ item.location }} - {% if country %} - {{ country.flag }} - {% elif item.online %} - 💻 Online - {% else %} - - country code {{ item.country }} not found - - {% endif %} - {% if item.free %} - | free to attend - {% elif item.price and item.currency %} - | price: {{ item.price }} {{ item.currency }} - {% endif %} -
-