Add page showing list of conferences

This commit is contained in:
Edward Betts 2023-11-20 20:48:42 +01:00
parent 71e9ce4af8
commit d67944a171
2 changed files with 28 additions and 9 deletions

View file

@ -92,8 +92,11 @@
<div class="container-fluid mt-2">
<h1>Agenda</h1>
<p>
<a href="/tools">&larr; personal tools</a> |
<a href="{{ url_for("travel_page") }}">travel</a>
<a href="/tools">&larr; personal tools</a>
|
<a href="{{ url_for("travel_list") }}">travel</a>
|
<a href="{{ url_for("conference_list") }}">conference</a>
</p>
<ul>

View file

@ -3,13 +3,15 @@
"""Web page to show upcoming events."""
import inspect
import os.path
import sys
import traceback
from datetime import datetime
from datetime import date, datetime
import flask
import werkzeug
import werkzeug.debug.tbtools
import yaml
import agenda.data
import agenda.travel
@ -55,18 +57,32 @@ async def index() -> str:
@app.route("/travel")
def travel_page() -> str:
def travel_list() -> str:
"""Page showing a list of upcoming travel."""
now = datetime.now()
config = agenda.data.get_config()
data_dir = config["data"]["personal-data"]
flights = agenda.travel.parse_yaml("flights", data_dir)
trains = agenda.travel.parse_yaml("trains", data_dir)
return flask.render_template(
"travel.html", today=now.date(), flights=flights, trains=trains
)
return flask.render_template("travel.html", flights=flights, trains=trains)
def as_date(d: date | datetime) -> date:
"""Date of event."""
return d.date() if isinstance(d, datetime) else d
@app.route("/conference")
def conference_list() -> str:
"""Page showing a list of conferences."""
config = agenda.data.get_config()
data_dir = config["data"]["personal-data"]
filepath = os.path.join(data_dir, "conferences.yaml")
item_list = yaml.safe_load(open(filepath))["conferences"]
item_list.sort(key=lambda conf: as_date(conf["start"]))
return flask.render_template("conference_list.html", item_list=item_list)
if __name__ == "__main__":