mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
store methods on load
This commit is contained in:
parent
926f56bb41
commit
905b164ecb
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user