From 5dc9414d9fe790142545b233dcd02d1c355d0ca0 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 19 Oct 2021 21:06:52 +0800 Subject: Flask web server prototype --- jimbrella/config.py | 1 + jimbrella/templates/index.html | 23 +++++++++++++++++++++++ jimbrella/utils.py | 6 ++++++ jimbrella/web.py | 25 +++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 jimbrella/config.py create mode 100644 jimbrella/templates/index.html create mode 100644 jimbrella/utils.py create mode 100644 jimbrella/web.py diff --git a/jimbrella/config.py b/jimbrella/config.py new file mode 100644 index 0000000..53dd2bb --- /dev/null +++ b/jimbrella/config.py @@ -0,0 +1 @@ +DATABASE_PATH = "/home/fkfd/p/jimbrella/jimbrella.db.csv" diff --git a/jimbrella/templates/index.html b/jimbrella/templates/index.html new file mode 100644 index 0000000..0304499 --- /dev/null +++ b/jimbrella/templates/index.html @@ -0,0 +1,23 @@ + + + + JI Umbrella + + +

JI Umbrella Overview

+ + + + + + + + + + + + + +
TotalAvailableLentOverdue
{{ total }}{{ available }}{{ lent }}{{ overdue }}
+ + diff --git a/jimbrella/utils.py b/jimbrella/utils.py new file mode 100644 index 0000000..a9f4623 --- /dev/null +++ b/jimbrella/utils.py @@ -0,0 +1,6 @@ +def group_by_status(umbrellas: list) -> dict: + keys = set([umb["status"] for umb in umbrellas]) + statuses = {} + for key in keys: + statuses[key] = [umb for umb in umbrellas if umb["status"] == key] + return statuses diff --git a/jimbrella/web.py b/jimbrella/web.py new file mode 100644 index 0000000..6446329 --- /dev/null +++ b/jimbrella/web.py @@ -0,0 +1,25 @@ +from flask import Flask, request, render_template +from .database import Database +from .utils import group_by_status +from .config import * + +db = Database(DATABASE_PATH) + +app = Flask("jimbrella") + + +@app.route("/") +def index(): + umbrellas = db.read() + statuses = group_by_status(umbrellas) + return render_template( + "index.html", + total=len(umbrellas), + available=len(statuses["available"]), + lent=len(statuses["lent"]), + overdue="Not Yet Implemented", + ) + + +if __name__ == "__main__": + app.run() -- cgit v1.2.3