From 88e8771b51a2550d112cb3fb3a64e330d6c1af79 Mon Sep 17 00:00:00 2001 From: pjpatil12 Date: Tue, 24 Mar 2026 16:56:23 +0530 Subject: [PATCH] add log file function --- app.log | 0 model/Log.py | 21 +++++++++------------ templates/edit_invoice.html | 9 ++++++--- 3 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 app.log diff --git a/app.log b/app.log deleted file mode 100644 index e69de29..0000000 diff --git a/model/Log.py b/model/Log.py index 504ba23..d3ed22f 100644 --- a/model/Log.py +++ b/model/Log.py @@ -14,22 +14,24 @@ class LogHelper: logData.WriteLog(action, details="") class LogData: - filepath = "" timestamp = None def __init__(self): self.filepath = FolderAndFile.get_activity_log_path('activity.log') self.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + self.user = LogData.get_current_user() + + @staticmethod + def get_current_user(): if hasattr(current_user, "cn") and current_user.cn: - self.user = current_user.cn + return current_user.cn elif hasattr(current_user, "username") and current_user.username: - self.user = current_user.username + return current_user.username elif hasattr(current_user, "sAMAccountName") and current_user.sAMAccountName: - self.user = current_user.sAMAccountName - else: - self.user = "Unknown" + return current_user.sAMAccountName + return "Unknown" def WriteLog(self, action, details=""): """Log user actions with timestamp, user, action, and details.""" @@ -42,7 +44,6 @@ class LogData: f"Details: {details}\n" ) - def GetActivitiesLog(self): logs = [] @@ -60,7 +61,6 @@ class LogData: return logs def GetFilteredActivitiesLog(self, startDate, endDate, userName): - filtered_logs = self.GetActivitiesLog() # Date filter @@ -69,17 +69,14 @@ class LogData: start_dt = datetime.strptime(startDate, "%Y-%m-%d") if startDate else datetime.min end_dt = datetime.strptime(endDate, "%Y-%m-%d") if endDate else datetime.max - filtered_logs = [ log for log in filtered_logs if start_dt <= datetime.strptime(log["timestamp"], "%Y-%m-%d %H:%M:%S") <= end_dt ] - except Exception as e: print("Date filter error:", e) - #Why catching all exceptions? Need to handle specific exceptions - + # Username filter if userName: filtered_logs = [log for log in filtered_logs if userName.lower() in log["user"].lower()] diff --git a/templates/edit_invoice.html b/templates/edit_invoice.html index 6d1c245..f8ab8f8 100644 --- a/templates/edit_invoice.html +++ b/templates/edit_invoice.html @@ -7,6 +7,7 @@ Edit Invoice + @@ -204,15 +205,17 @@ type: "POST", url: $(this).attr("action"), data: $(this).serialize(), + dataType: 'json', // ensure JSON is returned success: function (response) { if (response.status === "success") { - $("#invoiceSuccessAlert").fadeIn().delay(3000).fadeOut(); alert("Invoice updated successfully!"); // <-- Popup alert - } + // ✅ Redirect to Add Invoice page (table part visible) + window.location.href = "{{ url_for('invoice.add_invoice') }}#addTable"; + } }, error: function (xhr) { - alert("Error: " + xhr.responseJSON.message); + alert("Error: " + xhr.responseJSON?.message || "Something went wrong!"); } }); });