diff options
Diffstat (limited to 'jimbrella/admin_log.py')
-rw-r--r-- | jimbrella/admin_log.py | 60 |
1 files 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() |