scrapple/app.py

39 lines
808 B
Python
Raw Normal View History

2021-05-22 19:23:17 +00:00
import csv
2021-05-22 18:29:40 +00:00
from flask import Flask, render_template
app = Flask(__name__)
2021-05-23 02:42:39 +00:00
_employees = {}
2021-05-22 18:29:40 +00:00
2021-05-23 02:18:20 +00:00
def employees():
2021-05-23 02:42:39 +00:00
# thanks to http://www.figmentfly.com/bb/badguys3.html for names
global _employees
if not _employees:
with open("data/employees.csv") as f:
_employees = {e["id"]: e for e in csv.DictReader(f)}
return _employees
2021-05-23 02:18:20 +00:00
2021-05-22 18:29:40 +00:00
@app.route("/")
def index():
return render_template("index.html")
@app.route("/about")
def about():
return render_template("about.html")
2021-05-22 19:23:17 +00:00
@app.route("/staff")
def staff():
2021-05-23 02:42:39 +00:00
return render_template("staff.html", employees=employees().values())
2021-05-22 19:23:17 +00:00
2021-05-23 02:42:39 +00:00
@app.route("/staff/<id_>")
def staff_detail(id_):
if employee := employees().get(id_):
return render_template("staff_detail.html", employee=employee)
else:
raise 404