Link from accommodation list to trip pages

Closes: #109
This commit is contained in:
Edward Betts 2024-01-14 17:57:02 +00:00
parent 31e8197c79
commit 283a9d0b27
3 changed files with 24 additions and 7 deletions

View file

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% from "macros.html" import accommodation_row with context %} {% from "macros.html" import trip_link, accommodation_row with context %}
{% block style %} {% block style %}
{% set column_count = 7 %} {% set column_count = 8 %}
<style> <style>
.grid-container { .grid-container {
display: grid; display: grid;
@ -23,7 +23,10 @@
{% macro section(heading, item_list, badge) %} {% macro section(heading, item_list, badge) %}
{% if item_list %} {% if item_list %}
<div class="heading"><h2>{{heading}}</h2></div> <div class="heading"><h2>{{heading}}</h2></div>
{% for item in item_list %}{{ accommodation_row(item, badge) }}{% endfor %} {% for item in item_list %}
{{ accommodation_row(item, badge) }}
<div class="grid-item">{% if item.linked_trip %} trip: {{ trip_link(item.linked_trip) }} {% endif %}</div>
{% endfor %}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}

View file

@ -27,7 +27,9 @@
<div class="heading"><h2>{{ heading }}</h2></div> <div class="heading"><h2>{{ heading }}</h2></div>
{% for item in item_list %} {% for item in item_list %}
{{ conference_row(item, badge) }} {{ conference_row(item, badge) }}
<div class="grid-item">{% if item.trip %} trip: {{ trip_link(item.trip) }} {% endif %}</div> <div class="grid-item">
{% if item.linked_trip %} trip: {{ trip_link(item.linked_trip) }} {% endif %}
</div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}

View file

@ -104,9 +104,9 @@ def conference_list() -> str:
filepath = os.path.join(data_dir, "conferences.yaml") filepath = os.path.join(data_dir, "conferences.yaml")
item_list = yaml.safe_load(open(filepath)) item_list = yaml.safe_load(open(filepath))
today = date.today() today = date.today()
trip_list = agenda.trip.build_trip_list()
conference_trip_lookup = {} conference_trip_lookup = {}
for trip in trip_list: for trip in agenda.trip.build_trip_list():
for trip_conf in trip.conferences: for trip_conf in trip.conferences:
key = (trip_conf["start"], trip_conf["name"]) key = (trip_conf["start"], trip_conf["name"])
conference_trip_lookup[key] = trip conference_trip_lookup[key] = trip
@ -117,7 +117,7 @@ def conference_list() -> str:
key = (conf["start"], conf["name"]) key = (conf["start"], conf["name"])
if this_trip := conference_trip_lookup.get(key): if this_trip := conference_trip_lookup.get(key):
conf["trip"] = this_trip conf["linked_trip"] = this_trip
item_list.sort(key=operator.itemgetter("start_date")) item_list.sort(key=operator.itemgetter("start_date"))
@ -157,6 +157,18 @@ def accommodation_list() -> str:
if stay["country"] != "gb" if stay["country"] != "gb"
) )
trip_lookup = {}
for trip in agenda.trip.build_trip_list():
for trip_stay in trip.accommodation:
key = (trip_stay["from"], trip_stay["name"])
trip_lookup[key] = trip
for item in items:
key = (item["from"], item["name"])
if this_trip := trip_lookup.get(key):
item["linked_trip"] = this_trip
return flask.render_template( return flask.render_template(
"accommodation.html", "accommodation.html",
items=items, items=items,