From 1b9ca41b4690cbb635fe50e621b664ff14ec31b8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 2 Dec 2021 09:52:30 +0100 Subject: [PATCH] added setup function to notification method and added calls to deliver_method --- InvenTree/common/notifications.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/InvenTree/common/notifications.py b/InvenTree/common/notifications.py index 3478a71b32..1c0545c63e 100644 --- a/InvenTree/common/notifications.py +++ b/InvenTree/common/notifications.py @@ -34,6 +34,9 @@ class NotificationMethod: def get_recipients(self): raise NotImplementedError('The `get_recipients` method must be implemented!') + def setup(self): + return True + def cleanup(self): return True @@ -136,6 +139,9 @@ def deliver_notification(cls: NotificationMethod, obj, entry_name: str, receiver # Log start logger.info(f"Notify users via '{method.method_name}' for notification '{entry_name}' for '{str(obj)}'") + # Run setup for delivery method + method.setup() + success = True success_count = 0 @@ -154,6 +160,9 @@ def deliver_notification(cls: NotificationMethod, obj, entry_name: str, receiver else: raise NotImplementedError('No delivery method found') + # Run cleanup for delivery method + method.cleanup() + # Log results logger.info(f"Notified {success_count} users via '{method.method_name}' for notification '{entry_name}' for '{str(obj)}' successfully") if not success: