From e3f34fbd51efabccbe0e902b42ff452f4326b1e2 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 28 Oct 2021 10:43:16 +0800 Subject: Make AdminLog._write less repetitive --- jimbrella/admin_log.py | 29 ++++++++++++++++++----------- 1 file 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) -- cgit v1.2.3