Programme and collection templates

This commit is contained in:
Luke Murphy 2020-04-04 21:34:32 +02:00
parent b461658c62
commit 70dadaf624
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
8 changed files with 80 additions and 20 deletions

View File

@ -2,10 +2,10 @@
from csv import DictReader from csv import DictReader
from os import listdir from os import listdir
from os.path import basename, dirname, splitext from os.path import basename, dirname
from pathlib import Path from pathlib import Path
from flask import Flask, render_template from flask import Flask, abort, render_template
from ruamel.yaml import YAML from ruamel.yaml import YAML
app = Flask(__name__) app = Flask(__name__)
@ -13,6 +13,27 @@ cwd = dirname(Path(__file__).absolute())
yaml = YAML() yaml = YAML()
def get_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 programmes
def get_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 collection
@app.route("/") @app.route("/")
def about(): def about():
return render_template("about.html") return render_template("about.html")
@ -20,24 +41,24 @@ def about():
@app.route("/programmes") @app.route("/programmes")
def programmes(): def programmes():
programmes = [] programmes = get_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) return render_template("programmes.html", programmes=programmes)
@app.route("/programme/<name>")
def programme(name):
cleaned_name = name.replace("-", " ").lower()
programmes = get_programmes()
for programme in programmes:
cleaned_programme = programme.get("title", "").lower()
if cleaned_name == cleaned_programme:
return render_template("programme.html", programme=programme)
abort(404, description="Programme not found")
@app.route("/collection") @app.route("/collection")
def collection(): def collection():
collection = [] collection = get_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) return render_template("collection.html", collection=collection)

View File

@ -26,6 +26,18 @@ body {
animation-duration: 120s; animation-duration: 120s;
} }
ul {
padding-left: 0;
}
ul li {
list-style: none;
}
#hbbs-logo {
width: 90%;
}
html * { html * {
border: 1px black solid; border: 1px black solid;
} }

View File

@ -1,5 +1,11 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
<p>TODO: home page</p> <p>
This isnt another link dump, nor is it an all-you-can-eat streaming site. We
have files and we want to share them. The homebrew bioscoop offers programmes
made by viewers, for viewers. Our programmes are cu- rated playlists of films
in our collection. Playlists that en- courage play, sociality through the
things we share. Download a programme, watch it, make a programme, share it.
</p>
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
{% block content %} {% block content %}
<ul> <ul>
{% for film in collection %} {% for film in collection %}
<li>{{ film }}</li> <li>{{ film.Title }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -29,7 +29,8 @@
<div class="row"> <div class="row">
<div id="navigation" class="col-md-4"> <div id="navigation" class="col-md-4">
<img <img
class="img-fluid" id="hbbs-logo"
class="img-fluid mx-auto d-block"
src="/static/images/logo.png" src="/static/images/logo.png"
alt="hbbs logo" alt="hbbs logo"
/> />

View File

@ -1,5 +1,5 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
<p>TODO: participate page</p> <p>Invite only for now...</p>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,12 @@
{% extends "layout.html" %}
{% block content %}
<h1> <a href="/programme/{{ programme.title | replace(' ', '-') | lower }}">{{ programme.title }}</a> </h1>
<h2> {{ programme.tagline }} </h2>
<ul>
{% for film in programme.films %}
<li>{{ film }}</li>
{% endfor %}
</ul>
<a href="/programmes">All programmes...</a>
{% endblock %}

View File

@ -3,7 +3,15 @@
{% block content %} {% block content %}
<ul> <ul>
{% for programme in programmes %} {% for programme in programmes %}
<li>{{ programme }}</li> <li>
<h1> <a href="/programme/{{ programme.title | replace(' ', '-') | lower }}">{{ programme.title }}</a> </h1>
<h2> {{ programme.tagline }} </h2>
<ul>
{% for film in programme.films %}
<li>{{ film }}</li>
{% endfor %}
</ul>
</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} {% endblock %}