From 21880c47ba381221b9a269c0aa2e83b11d8eb945 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 20 Oct 2021 00:03:07 +0800 Subject: More work on web console --- jimbrella/config.py | 4 ++++ jimbrella/static/jimbrella.css | 34 ++++++++++++++++++++++++++++++++++ jimbrella/templates/index.html | 33 ++++++++++++++++++--------------- jimbrella/utils.py | 14 ++++++++++++++ jimbrella/web.py | 4 ++-- 5 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 jimbrella/static/jimbrella.css (limited to 'jimbrella') diff --git a/jimbrella/config.py b/jimbrella/config.py index 53dd2bb..26111f1 100644 --- a/jimbrella/config.py +++ b/jimbrella/config.py @@ -1 +1,5 @@ +# database DATABASE_PATH = "/home/fkfd/p/jimbrella/jimbrella.db.csv" + +# rules of service +DUE_HOURS = 72 diff --git a/jimbrella/static/jimbrella.css b/jimbrella/static/jimbrella.css new file mode 100644 index 0000000..06c7225 --- /dev/null +++ b/jimbrella/static/jimbrella.css @@ -0,0 +1,34 @@ +body { + font-family: sans-serif; +} + +table.overview { + border: 2px solid; + text-align: center; +} + +td { + border: 1px solid; + padding-top: 1em; + padding-bottom: 1em; + width: 6em; +} + +#container { + position: relative; +} + +/* Desktop */ +@media(min-width: 1081px) { + #container { + width: 60%; + left: 20%; + } +} + +/* Mobile compatibility */ +@media (max-width: 1080px) { + #container { + padding: 1em; + } +} diff --git a/jimbrella/templates/index.html b/jimbrella/templates/index.html index 0304499..00036fc 100644 --- a/jimbrella/templates/index.html +++ b/jimbrella/templates/index.html @@ -2,22 +2,25 @@ JI Umbrella + -

JI Umbrella Overview

- - - - - - - - - - - - - -
TotalAvailableLentOverdue
{{ total }}{{ available }}{{ lent }}{{ overdue }}
+
+

JI Umbrella Overview

+ + + + + + + + + + + + + +
TotalAvailableLentOverdue
{{ total }}{{ available }}{{ lent }}{{ overdue }}
+
diff --git a/jimbrella/utils.py b/jimbrella/utils.py index a9f4623..09f0ae2 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,6 +1,20 @@ +from datetime import datetime, timedelta +from .config import * + + 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 + + +def find_overdue(umbrellas: list) -> list: + now = datetime.now() + return [ + umb + for umb in umbrellas + if umb["lent_at"] is not None + and now - umb["lent_at"] > timedelta(hours=DUE_HOURS) + ] diff --git a/jimbrella/web.py b/jimbrella/web.py index 6446329..006c66c 100644 --- a/jimbrella/web.py +++ b/jimbrella/web.py @@ -1,6 +1,6 @@ from flask import Flask, request, render_template from .database import Database -from .utils import group_by_status +from .utils import group_by_status, find_overdue from .config import * db = Database(DATABASE_PATH) @@ -17,7 +17,7 @@ def index(): total=len(umbrellas), available=len(statuses["available"]), lent=len(statuses["lent"]), - overdue="Not Yet Implemented", + overdue=len(find_overdue(umbrellas)), ) -- cgit v1.2.3