diff options
Diffstat (limited to 'jimbrella')
-rw-r--r-- | jimbrella/admin_log.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py index d1c57c2..2d130c7 100644 --- a/jimbrella/admin_log.py +++ b/jimbrella/admin_log.py @@ -2,6 +2,7 @@ import csv import os from datetime import datetime from .lockfile import Lockfile +from .utils import human_datetime class AdminLog: @@ -80,6 +81,40 @@ class AdminLog: f.close() return logs + def read(self) -> list: + """Human-friendly representation of each of the admin log entries.""" + logs = self._read() + friendly_logs = [] + for entry in logs: + event = entry["event"] + tenant_info = "(ID: {tenant_id}, phone: {tenant_phone})" + if event == "TAKEAWAY": + description = ( + "{tenant_name} borrowed umbrella #{serial}. " + tenant_info + ) + elif event == "GIVEBACK": + description = ( + "{tenant_name} returned umbrella #{serial}. " + tenant_info + ) + elif event == "OVERDUE": + description = ( + "{tenant_name} missed the due for umbrella #{serial}. " + + tenant_info + ) + elif event == "ADMIN_MODIFY_DB": + description = "{admin_name} changed {column} of umbrella #{serial} from {past_value} to {new_value}." + + friendly_logs.append( + { + "date_str": human_datetime(entry["date"]), + "event": event, + "description": description.format(**entry), + "note": entry["note"], + } + ) + + return friendly_logs + def log(self, event: str, entry: dict, date=None, note="") -> None: """Serialize a log, and append it to the end of the log file. |