store methods on load

This commit is contained in:
Matthias 2022-04-03 03:47:48 +02:00
parent 926f56bb41
commit 905b164ecb
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 22 additions and 2 deletions

View File

@ -31,6 +31,8 @@ class InvenTreeConfig(AppConfig):
if not isInTestMode(): # pragma: no cover
self.update_exchange_rates()
self.collect_notification_methods()
if canAppAccessDatabase() or settings.TESTING_ENV:
self.add_user_on_startup()
@ -197,3 +199,11 @@ class InvenTreeConfig(AppConfig):
# do not try again
settings.USER_ADDED = True
def collect_notification_methods(self):
"""
Collect all notification methods
"""
from common.notifications import storage
storage.collect()

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)