diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-28 10:43:16 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-28 10:43:16 +0800 |
commit | e3f34fbd51efabccbe0e902b42ff452f4326b1e2 (patch) | |
tree | 67c792d43d0de01d5af748a45b76243fe1dadc33 /jimbrella | |
parent | 769f43a6e09ef9c50884a3cda463175ae09d1600 (diff) |
Make AdminLog._write less repetitive
Diffstat (limited to 'jimbrella')
-rw-r--r-- | jimbrella/admin_log.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py index 4cc9b16..aea1a27 100644 --- a/jimbrella/admin_log.py +++ b/jimbrella/admin_log.py @@ -9,7 +9,8 @@ class AdminLog: The file is intended to be read, deserialized, and represented in a user-friendly format to an admin on the web console. The file format is csv, but the number and meanings of columns may - not be uniform for all rows. + not be uniform for all rows. This is why it cannot be a subclass of CsvTable, which expects the + columns to be uniform. For each row, there are a minimum of three columns. The first column is called the "event". It describes the log entry by and large. What other columns in the row represent depends on @@ -96,19 +97,25 @@ class AdminLog: info = [] if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"): info = [ - entry["serial"], - entry["tenant_name"], - entry["tenant_id"], - entry["tenant_phone"], - entry["tenant_email"], + entry[col] + for col in [ + "serial", + "tenant_name", + "tenant_id", + "tenant_phone", + "tenant_email", + ] ] elif event == "ADMIN_MODIFY_DB": info = [ - entry["admin_name"], - entry["serial"], - entry["column"], - entry["past_value"], - entry["new_value"], + entry[col] + for col in [ + "admin_name", + "serial", + "column", + "past_value", + "new_value", + ] ] line.extend(info) |