From 16448c30fb4d01d3ceb8209ea8b640b2601e897d Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 28 Oct 2021 22:07:53 +0800 Subject: Database keeps admin log --- jimbrella/database.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'jimbrella') diff --git a/jimbrella/database.py b/jimbrella/database.py index 9ca3c5b..410985e 100644 --- a/jimbrella/database.py +++ b/jimbrella/database.py @@ -1,7 +1,8 @@ from datetime import datetime, timedelta from .csv_table import CsvTable +from .admin_log import AdminLog from .utils import human_datetime, human_timedelta -from .config import DUE_HOURS +from .config import DUE_HOURS, ADMIN_LOG_PATH from .exceptions import * STATUSES = ["available", "lent", "overdue", "maintenance", "withheld", "unknown"] @@ -60,6 +61,7 @@ class Database(CsvTable): }, ], ) + self.admin_log = AdminLog(ADMIN_LOG_PATH) def _find_by_serial(self, serial: int) -> dict: """Given a serial number, returns an umbrella with such serial. @@ -208,6 +210,7 @@ class Database(CsvTable): umb["tenant_email"] = tenant_email umb["lent_at"] = date self._update(umb) + self.admin_log.log("TAKEAWAY", umb) def give_back(self, serial) -> None: """When a user has returned an umbrella.""" @@ -221,6 +224,7 @@ class Database(CsvTable): umb[key] = "" umb["lent_at"] = None self._update(umb) + self.admin_log.log("GIVEBACK", umb) def mark_overdue(self, serial) -> None: """When an umbrella is overdue, change its status to "overdue".""" @@ -231,3 +235,4 @@ class Database(CsvTable): raise UmbrellaStatusError umb["status"] = "overdue" self._update(umb) + self.admin_log.log("OVERDUE", umb) -- cgit v1.2.3