2023-04-09 13:38:07 +11:00
|
|
|
import re
|
2023-04-09 06:17:34 +11:00
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
from logging import config
|
|
|
|
import yaml
|
|
|
|
from flask import Flask, render_template, redirect, request, url_for
|
|
|
|
from thsf.backend import Backend
|
|
|
|
from thsf.schedule import Schedule
|
2023-04-09 13:38:07 +11:00
|
|
|
from thsf.navbar import Navbar
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Configuration
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
class AppConfig:
|
|
|
|
""" Flask application config """
|
|
|
|
CONFIG_FILENAME = "config.yml"
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Application
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
logger = logging.getLogger('wsgi')
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Local configuration
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
app.config.from_object(__name__ + '.AppConfig')
|
|
|
|
try:
|
|
|
|
with open(app.config["CONFIG_FILENAME"], mode="r", encoding="utf-8") as local_config_file:
|
|
|
|
app.local_config = yaml.load(local_config_file, Loader=yaml.SafeLoader)
|
|
|
|
app.config["SECRET_KEY"] = app.local_config["app"]["secret_key"]
|
|
|
|
app.config["LANGUAGES"] = app.local_config["app"]["languages"]
|
|
|
|
config.dictConfig(app.local_config["log"])
|
|
|
|
backend = Backend(url=app.local_config["pretalx"]["url"],
|
|
|
|
apiprefix=app.local_config["pretalx"]["apiprefix"],
|
|
|
|
apikey=app.local_config["pretalx"]["apikey"])
|
|
|
|
schedule = Schedule()
|
2023-04-09 13:38:07 +11:00
|
|
|
navbar = Navbar(config=app.local_config["navbar"])
|
2023-04-09 06:17:34 +11:00
|
|
|
except Exception as err:
|
|
|
|
logger.critical("[{}] {}".format(err.__class__, str(err)))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Tools
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def page_not_found(err):
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
2023-04-09 22:13:29 +11:00
|
|
|
def get_slots():
|
|
|
|
return backend.get(endpoint=f"events/{app.local_config['pretalx']['event']}/schedules/{app.local_config['pretalx']['schedule']}").json()
|
|
|
|
|
2023-04-09 11:12:29 +11:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Custom filters
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
@app.template_filter('date2dmyhm')
|
|
|
|
def date2dmyhm(date):
|
|
|
|
splitted_date = date.split("-")
|
|
|
|
splitted_time = splitted_date[2].split("T")[1].split(":")
|
|
|
|
year, month, day = (splitted_date[0],
|
|
|
|
splitted_date[1],
|
|
|
|
splitted_date[2].split("T")[0])
|
|
|
|
hour, minutes = (splitted_time[0], splitted_time[1].split("+")[0])
|
|
|
|
return f"{day}/{month} {hour}:{minutes}"
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 21:37:50 +11:00
|
|
|
@app.template_filter('date2dayclass')
|
|
|
|
def date2dayclass(date):
|
|
|
|
classes = {"26/05": "bg1",
|
|
|
|
"27/05": "bg2",
|
|
|
|
"28/05": "bg3",}
|
|
|
|
splitted_date = date.split("-")
|
|
|
|
month, day = (splitted_date[1],
|
|
|
|
splitted_date[2].split("T")[0])
|
|
|
|
return classes[f"{day}/{month}"]
|
|
|
|
|
2023-04-09 11:12:29 +11:00
|
|
|
@app.template_filter('toicon')
|
|
|
|
def date2dmyhm(slot_type):
|
|
|
|
slot_types = {"Projection": "fa-solid fa-film",
|
|
|
|
"Presentation Courte": "fa-solid fa-person-chalkboard",
|
|
|
|
"DJ Set": "fa-solid fa-guitar",
|
|
|
|
"Concert": "fa-solid fa-guitar",
|
|
|
|
"Présentation": "fa-solid fa-person-chalkboard",
|
|
|
|
"Table Ronde": "fa-solid fa-users-line",
|
|
|
|
"Atelier": "fa-solid fa-screwdriver-wrench",
|
|
|
|
"Exposition": "fa-solid fa-palette"}
|
|
|
|
return slot_types[slot_type]
|
2023-04-09 13:38:07 +11:00
|
|
|
|
2023-04-09 06:17:34 +11:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Routes
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
@app.route('/favicon.ico', methods=['GET'])
|
|
|
|
def favicon():
|
|
|
|
return redirect(url_for('static', filename='images/favicon.png'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def index():
|
2023-04-09 13:38:07 +11:00
|
|
|
return render_template("index.html",
|
|
|
|
navbar=navbar.get_from_page(page="/"))
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
@app.route('/planning', methods=['GET'])
|
|
|
|
def planning():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
2023-04-09 13:38:07 +11:00
|
|
|
return render_template("planning.html",
|
2023-04-09 17:29:44 +11:00
|
|
|
slots=sorted(slots["slots"],
|
2023-04-09 22:13:29 +11:00
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
2023-04-09 13:38:07 +11:00
|
|
|
navbar=navbar.get_from_page(page="/planning"))
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/place', methods=['GET'])
|
|
|
|
def place():
|
|
|
|
return render_template("index.html",
|
|
|
|
navbar=navbar.get_from_page(page="/place"))
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/food', methods=['GET'])
|
|
|
|
def food():
|
|
|
|
return render_template("index.html",
|
|
|
|
navbar=navbar.get_from_page(page="/food"))
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/goodies', methods=['GET'])
|
|
|
|
def goodies():
|
2023-04-09 21:19:55 +11:00
|
|
|
return render_template("goodies.html",
|
2023-04-09 13:38:07 +11:00
|
|
|
navbar=navbar.get_from_page(page="/goodies"))
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
@app.route('/concerts', methods=['GET'])
|
|
|
|
def concerts():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/concerts"),
|
|
|
|
filter=["concerts", "dj set"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/workshops', methods=['GET'])
|
|
|
|
def workshops():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/workshops"),
|
|
|
|
filter=["workshop"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/screenings', methods=['GET'])
|
|
|
|
def screenings():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/screenings"),
|
|
|
|
filter=["screening"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
2023-04-09 13:38:07 +11:00
|
|
|
@app.route('/discussions', methods=['GET'])
|
|
|
|
def discussions():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/discussions"),
|
|
|
|
filter=["panel discussion"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
@app.route('/exhibitions', methods=['GET'])
|
|
|
|
def exhibitions():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/exhibitions"),
|
|
|
|
filter=["exhibition"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
@app.route('/talks', methods=['GET'])
|
|
|
|
def talks():
|
2023-04-09 22:13:29 +11:00
|
|
|
slots = get_slots()
|
|
|
|
return render_template("planning.html",
|
|
|
|
slots=sorted(slots["slots"],
|
|
|
|
key=lambda slot: slot["slot"]["start"]),
|
|
|
|
navbar=navbar.get_from_page(page="/talks"),
|
|
|
|
filter=["talk", "light talk"])
|
2023-04-09 06:17:34 +11:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# -- Main
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='127.0.0.1', port=5000, debug=True)
|