2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

store methods on load

This commit is contained in:
Matthias
2022-04-03 03:47:48 +02:00
parent 926f56bb41
commit 905b164ecb
2 changed files with 22 additions and 2 deletions

View File

@ -122,10 +122,18 @@ class BulkNotificationMethod(NotificationMethod):
raise NotImplementedError('The `send` method must be overriden!')
class MethodStorageClass:
liste = None
def collect(self):
storage.liste = inheritors(NotificationMethod) - IGNORED_NOTIFICATION_CLS
IGNORED_NOTIFICATION_CLS = set([
SingleNotificationMethod,
BulkNotificationMethod,
])
storage = MethodStorageClass()
class UIMessageNotification(SingleNotificationMethod):
@ -190,9 +198,11 @@ def trigger_notifaction(obj, category=None, obj_ref='pk', **kwargs):
# Collect possible methods
if delivery_methods is None:
delivery_methods = inheritors(NotificationMethod)
delivery_methods = storage.liste
else:
delivery_methods = (delivery_methods - IGNORED_NOTIFICATION_CLS)
for method in (delivery_methods - IGNORED_NOTIFICATION_CLS):
for method in delivery_methods:
logger.info(f"Triggering method '{method.METHOD_NAME}'")
try:
deliver_notification(method, obj, category, targets, context)