From 5305b0f49f7cf94a223bdbdd4f643fbbebca0f0b Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 4 Apr 2020 20:45:54 +0200 Subject: [PATCH] Wire up the basics --- fabfile.py | 1 + hbbs/server.py | 41 +++++++++++++++++-- hbbs/static/csv/{index.csv => collection.csv} | 0 hbbs/static/programmes/point-of-view.yml | 5 +++ hbbs/static/programmes/retellings.yml | 5 +++ hbbs/templates/collection.html | 6 ++- hbbs/templates/layout.html | 7 +++- hbbs/templates/programmes.html | 6 ++- requirements.txt | 1 + 9 files changed, 66 insertions(+), 6 deletions(-) rename hbbs/static/csv/{index.csv => collection.csv} (100%) create mode 100644 hbbs/static/programmes/point-of-view.yml create mode 100644 hbbs/static/programmes/retellings.yml diff --git a/fabfile.py b/fabfile.py index bc422bb..fbad203 100644 --- a/fabfile.py +++ b/fabfile.py @@ -8,5 +8,6 @@ def hbbs(c): """Release hbbs.decentral1.se.""" with c.cd("/var/www/hbbs"): c.run("sudo -su www-data git pull origin master") + c.run("sudo -su www-data .venv/bin/pip install -r requirements.txt") c.run("sudo supervisorctl restart apps:hbbs") c.run("sudo systemctl reload nginx") diff --git a/hbbs/server.py b/hbbs/server.py index dbe73fa..e84d010 100644 --- a/hbbs/server.py +++ b/hbbs/server.py @@ -1,11 +1,46 @@ """Flask server.""" +from csv import DictReader +from os import listdir +from os.path import basename, dirname, splitext +from pathlib import Path + from flask import Flask, render_template +from ruamel.yaml import YAML app = Flask(__name__) +cwd = dirname(Path(__file__).absolute()) +yaml = YAML() @app.route("/") -def home(): - """Serve the home page.""" - return render_template("index.html") +def about(): + return render_template("about.html") + + +@app.route("/programmes") +def programmes(): + programmes = [] + path = cwd / Path("static/programmes/") + for file in listdir(path): + with open(path / file, "r") as handle: + contents = handle.read() + loaded = yaml.load(contents) + programmes.append(loaded) + return render_template("programmes.html", programmes=programmes) + + +@app.route("/collection") +def collection(): + collection = [] + path = cwd / Path("static/csv/collection.csv") + with open(path, "r") as handle: + reader = DictReader(handle) + for row in reader: + collection.append(row) + return render_template("collection.html", collection=collection) + + +@app.route("/participate") +def participate(): + return render_template("participate.html") diff --git a/hbbs/static/csv/index.csv b/hbbs/static/csv/collection.csv similarity index 100% rename from hbbs/static/csv/index.csv rename to hbbs/static/csv/collection.csv diff --git a/hbbs/static/programmes/point-of-view.yml b/hbbs/static/programmes/point-of-view.yml new file mode 100644 index 0000000..119b347 --- /dev/null +++ b/hbbs/static/programmes/point-of-view.yml @@ -0,0 +1,5 @@ +--- +title: Point of View +tagline: Perspective makes all the difference +films: + - Rear Window diff --git a/hbbs/static/programmes/retellings.yml b/hbbs/static/programmes/retellings.yml new file mode 100644 index 0000000..ce64659 --- /dev/null +++ b/hbbs/static/programmes/retellings.yml @@ -0,0 +1,5 @@ +--- +title: Retellings +tagline: Extending the story with the second film +films: + - La Jetée & 12 Monkeys diff --git a/hbbs/templates/collection.html b/hbbs/templates/collection.html index 7022f88..cc49016 100644 --- a/hbbs/templates/collection.html +++ b/hbbs/templates/collection.html @@ -1,5 +1,9 @@ {% extends "layout.html" %} {% block content %} -

TODO: collection page

+ {% endblock %} diff --git a/hbbs/templates/layout.html b/hbbs/templates/layout.html index b01cd7e..f853c2b 100644 --- a/hbbs/templates/layout.html +++ b/hbbs/templates/layout.html @@ -14,7 +14,12 @@
{% block content %}{% endblock %} diff --git a/hbbs/templates/programmes.html b/hbbs/templates/programmes.html index 3e06cae..cf18e69 100644 --- a/hbbs/templates/programmes.html +++ b/hbbs/templates/programmes.html @@ -1,5 +1,9 @@ {% extends "layout.html" %} {% block content %} -

TODO: programmes page

+ {% endblock %} diff --git a/requirements.txt b/requirements.txt index 6215b57..227d265 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ fabric==2.5.0 flask==1.1.1 gunicorn==20.0.4 +ruamel.yaml==0.16.10