diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-28 11:38:39 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-28 13:49:55 +0800 |
commit | f378751a2b0ea4959f80e250afa8b2845f9f286b (patch) | |
tree | 3af75f490dc9f91206e47edaf0a4b1a306af6316 /jimbrella | |
parent | e3f34fbd51efabccbe0e902b42ff452f4326b1e2 (diff) |
AdminLog: _write is now called log and takes one entry only
Diffstat (limited to 'jimbrella')
-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() |