summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-24 16:14:54 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-24 16:14:54 +0800
commit8a9e80d9a2d823c90ccbbdbca268e6c65a8ac31b (patch)
tree5041485a5971d6407e4406dc6a0a9a99639edef6 /jimbrella
parentdd3f59fc9ab7218670cc6d4d25bcb471a708d4ea (diff)
Database.group_by_status lists all statuses
If there are no umbrellas that are overdue in the database, the behavior was to omit them from the returned dict. Now their values are []. Also, small comment fix.
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/database.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/jimbrella/database.py b/jimbrella/database.py
index f0d519e..f069229 100644
--- a/jimbrella/database.py
+++ b/jimbrella/database.py
@@ -23,7 +23,7 @@ class Database:
- serial | (id) unique identifier for the umbrella.
- alias | (string) future compatibility. a human readable (preferably cute) name
| for a particular umbrella
- - status | (string) one of ("available", "lent", "withheld", "maintenance",
+ - status | (string) one of ("available", "lent", "overdue", "maintenance",
| "withheld", "unknown")
| available : is in service on the stand
| lent : is in temporary possession of a user
@@ -181,7 +181,10 @@ class Database:
def group_by_status(umbrellas) -> dict:
"""(static method) Returns umbrellas grouped into a dict by their status."""
keys = set([umb["status"] for umb in umbrellas])
- statuses = {}
+ # initiate statuses: each status is []
+ statuses = dict.fromkeys(
+ ["available", "lent", "overdue", "withheld", "maintenance", "unknown"], []
+ )
for key in keys:
statuses[key] = [umb for umb in umbrellas if umb["status"] == key]
return statuses