diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 00:03:07 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 00:03:07 +0800 |
commit | 21880c47ba381221b9a269c0aa2e83b11d8eb945 (patch) | |
tree | 33a53fb6382b5163e98584dd649e02ad7ab998b8 | |
parent | eedc26ed8b2848487164614e49a4b5647d24c7d1 (diff) |
More work on web console
-rw-r--r-- | jimbrella.db.csv | 2 | ||||
-rw-r--r-- | jimbrella/config.py | 4 | ||||
-rw-r--r-- | jimbrella/static/jimbrella.css | 34 | ||||
-rw-r--r-- | jimbrella/templates/index.html | 33 | ||||
-rw-r--r-- | jimbrella/utils.py | 14 | ||||
-rw-r--r-- | jimbrella/web.py | 4 |
6 files changed, 73 insertions, 18 deletions
diff --git a/jimbrella.db.csv b/jimbrella.db.csv index 422962f..615d8b6 100644 --- a/jimbrella.db.csv +++ b/jimbrella.db.csv @@ -1,7 +1,7 @@ 1,,available,,,,,
2,,lent,Jim Brella,1337,10086,,2021-10-19T09:35:30
3,,available,,,,,
-4,,available,,,,,
+4,,lent,Big Chungus,420,10001,,1970-01-01T00:00:01
5,,available,,,,,
6,,available,,,,,
7,,available,,,,,
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 @@ <html> <head> <title>JI Umbrella</title> + <link rel="stylesheet" href="static/jimbrella.css" /> </head> <body> - <h1>JI Umbrella Overview</h1> - <table> - <tr> - <td>Total</td> - <td>Available</td> - <td>Lent</td> - <td>Overdue</td> - </tr> - <tr> - <td>{{ total }}</td> - <td>{{ available }}</td> - <td>{{ lent }}</td> - <td>{{ overdue }}</td> - </tr> - </table> + <div id="container"> + <h1>JI Umbrella Overview</h1> + <table class="overview"> + <tr> + <td>Total</td> + <td>Available</td> + <td>Lent</td> + <td>Overdue</td> + </tr> + <tr> + <td>{{ total }}</td> + <td>{{ available }}</td> + <td>{{ lent }}</td> + <td>{{ overdue }}</td> + </tr> + </table> + </div> </body> </html> 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)), ) |