diff options
Diffstat (limited to 'jimbrella')
-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 |
5 files changed, 72 insertions, 17 deletions
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)), ) |