From f378751a2b0ea4959f80e250afa8b2845f9f286b Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 28 Oct 2021 11:38:39 +0800 Subject: AdminLog: _write is now called log and takes one entry only --- jimbrella/admin_log.py | 60 +++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py index aea1a27..e30809e 100644 --- a/jimbrella/admin_log.py +++ b/jimbrella/admin_log.py @@ -80,47 +80,43 @@ class AdminLog: f.close() return logs - def _write(self, logs: list) -> None: - """Serialize logs. - - `logs` is a list of log entries, to be appended at the end of the log file. - """ + def log(self, entry: dict) -> None: + """Serialize a log, and append it to the end of the log file.""" # wait until database is locked for this write while not self.lockfile.lock(): continue with open(self.path, "a") as f: # append only writer = csv.writer(f) - for entry in logs: - event = entry["event"] - line = [event, entry["date"].isoformat()] - info = [] - if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"): - info = [ - entry[col] - for col in [ - "serial", - "tenant_name", - "tenant_id", - "tenant_phone", - "tenant_email", - ] + event = entry["event"] + line = [event, entry["date"].isoformat()] + info = [] + if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"): + info = [ + entry[col] + for col in [ + "serial", + "tenant_name", + "tenant_id", + "tenant_phone", + "tenant_email", ] - elif event == "ADMIN_MODIFY_DB": - info = [ - entry[col] - for col in [ - "admin_name", - "serial", - "column", - "past_value", - "new_value", - ] + ] + elif event == "ADMIN_MODIFY_DB": + info = [ + entry[col] + for col in [ + "admin_name", + "serial", + "column", + "past_value", + "new_value", ] + ] - line.extend(info) - line.append(entry["note"]) - writer.writerow(line) + line.extend(info) + line.append(entry["note"]) + writer.writerow(line) f.close() -- cgit v1.2.3