From f2194946f34e5b3259430ffaed72dc658123a46a Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 19 Feb 2022 22:19:57 +0800 Subject: Logger.read_admin/tenant --- jimbrella/logger.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'jimbrella/logger.py') diff --git a/jimbrella/logger.py b/jimbrella/logger.py index dc5f83c..e3d5f62 100644 --- a/jimbrella/logger.py +++ b/jimbrella/logger.py @@ -12,23 +12,29 @@ class Logger: """ self.path = path - def read(self, maxlogs=20, serial=None) -> Union[dict, list]: + def read(self, table, maxlogs=20, serial=None) -> Union[dict, list]: db = sqlite3.connect(self.path) db.row_factory = sqlite3.Row if serial is None: - data = db.execute("SELECT * FROM AdminLog ORDER BY serial DESC").fetchmany( + data = db.execute(f"SELECT * FROM {table} ORDER BY serial DESC").fetchmany( maxlogs ) else: data = db.execute( - "SELECT * FROM AdminLog WHERE serial = ?", (serial,) + f"SELECT * FROM {table} WHERE serial = ?", (serial,) ).fetchone() db.close() return data + def read_admin(self, maxlogs=20, serial=None) -> Union[dict, list]: + return self.read("AdminLog", maxlogs, serial) + + def read_tenant(self, maxlogs=20, serial=None) -> Union[dict, list]: + return self.read("TenantLog", maxlogs, serial) + def log_admin( - self, date: str, actor: str, umumbbid: int, umb_a: dict, umb_b: dict, note="" + self, date: str, actor: str, umbid: int, umb_a: dict, umb_b: dict, note="" ) -> None: """Logs admin operations in a database so they can be recalled and possibly undone. -- cgit v1.2.3