Add accommodation page

Closes: #88
This commit is contained in:
Edward Betts 2024-01-01 21:26:39 +00:00
parent ac1f279cb4
commit aa7d7b7e6c
6 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1,67 @@
{% extends "base.html" %}
{% block style %}
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(6, auto);
gap: 10px;
justify-content: start;
}
.grid-item {
/* Additional styling for grid items can go here */
}
.heading {
grid-column: 1 / 7; /* Spans from the 1st line to the 7th line */
}
</style>
{% endblock %}
{% macro row(item, badge) %}
<div class="grid-item text-end">{{ item.from.strftime("%a, %d %b %Y") }}</div>
<div class="grid-item text-end">{{ item.to.strftime("%a, %d %b") }}</div>
<div class="grid-item text-end">{{ (item.to.date() - item.from.date()).days }}</div>
<div class="grid-item">{{ item.name }}</div>
<div class="grid-item">{{ item.operator }}</div>
<div class="grid-item">{{ item.location }}</div>
{% endmacro %}
{% macro section(heading, item_list, badge) %}
{% if item_list %}
<div class="heading"><h2>{{heading}}</h2></div>
{% for item in item_list %}{{ row(item, badge) }}{% endfor %}
{% endif %}
{% endmacro %}
{% block content %}
<div class="container-fluid mt-2">
<h1>Accommodation</h1>
<p>
<a href="{{ url_for("index") }}">&larr; back to agenda</a>
|
<a href="{{ url_for("travel_list") }}">travel</a>
|
<a href="{{ url_for("conference_list") }}">conference</a>
|
<a href="{{ url_for("gaps_page") }}">gaps</a>
|
<strong>accommodation</strong>
</p>
<ul>
<li>Total nights away in 2024: {{ total_nights_2024 }}</li>
<li>Total nights abroad in 2024: {{ nights_abroad_2024 }}</li>
</ul>
<div class="grid-container">
{{ section("Accommodation", items) }}
</div>
</div>
{% endblock %}

View file

@ -61,6 +61,8 @@
<strong>conference</strong>
|
<a href="{{ url_for("gaps_page") }}">gaps</a>
|
<a href="{{ url_for("accommodation_list") }}">accommodation</a>
</p>
<div class="grid-container">

View file

@ -12,6 +12,8 @@
<a href="{{ url_for("conference_list") }}">conference</a>
|
<strong>gaps</strong>
|
<a href="{{ url_for("accommodation_list") }}">accommodation</a>
</p>

View file

@ -115,6 +115,8 @@
<a href="{{ url_for("conference_list") }}">conference</a>
|
<a href="{{ url_for("gaps_page") }}">gaps</a>
|
<a href="{{ url_for("accommodation_list") }}">accommodation</a>
</p>
<ul>

View file

@ -44,6 +44,8 @@
<a href="{{ url_for("conference_list") }}">conference</a>
|
<a href="{{ url_for("gaps_page") }}">gaps</a>
|
<a href="{{ url_for("accommodation_list") }}">accommodation</a>
</p>
<h3>flights</h3>

View file

@ -111,5 +111,30 @@ def conference_list() -> str:
)
@app.route("/accommodation")
def accommodation_list() -> str:
"""Page showing a list of past, present and future accommodation."""
data_dir = app.config["PERSONAL_DATA"]
items = agenda.travel.parse_yaml("accommodation", data_dir)
stays_in_2024 = [item for item in items if item["from"].year == 2024]
total_nights_2024 = sum(
(stay["to"].date() - stay["from"].date()).days for stay in stays_in_2024
)
nights_abroad_2024 = sum(
(stay["to"].date() - stay["from"].date()).days
for stay in stays_in_2024
if stay["country"] != "gb"
)
return flask.render_template(
"accommodation.html",
items=items,
total_nights_2024=total_nights_2024,
nights_abroad_2024=nights_abroad_2024,
)
if __name__ == "__main__":
app.run(host="0.0.0.0")