10
10
11
11
import common .models
12
12
import InvenTree .helpers
13
- from InvenTree .ready import isImportingData
13
+ from InvenTree .ready import isImportingData , isRebuildingData
14
14
from plugin import registry
15
15
from plugin .models import NotificationUserSetting , PluginConfig
16
16
from users .models import Owner
@@ -185,9 +185,20 @@ class MethodStorageClass:
185
185
Is initialized on startup as one instance named `storage` in this file.
186
186
"""
187
187
188
- liste = None
188
+ methods_list = None
189
189
user_settings = {}
190
190
191
+ @property
192
+ def methods (self ):
193
+ """Return all available methods.
194
+
195
+ This is cached, and stored internally.
196
+ """
197
+ if self .methods_list is None :
198
+ self .collect ()
199
+
200
+ return self .methods_list
201
+
191
202
def collect (self , selected_classes = None ):
192
203
"""Collect all classes in the environment that are notification methods.
193
204
@@ -196,7 +207,8 @@ def collect(self, selected_classes=None):
196
207
Args:
197
208
selected_classes (class, optional): References to the classes that should be registered. Defaults to None.
198
209
"""
199
- logger .debug ('Collecting notification methods' )
210
+ logger .debug ('Collecting notification methods...' )
211
+
200
212
current_method = (
201
213
InvenTree .helpers .inheritors (NotificationMethod ) - IGNORED_NOTIFICATION_CLS
202
214
)
@@ -219,8 +231,12 @@ def collect(self, selected_classes=None):
219
231
item .plugin = plugin () if plugin else None
220
232
filtered_list [ref ] = item
221
233
222
- storage .liste = list (filtered_list .values ())
223
- logger .info ('Found %s notification methods' , len (storage .liste ))
234
+ storage .methods_list = list (filtered_list .values ())
235
+
236
+ logger .info ('Found %s notification methods' , len (storage .methods_list ))
237
+
238
+ for item in storage .methods_list :
239
+ logger .debug (' - %s' , str (item ))
224
240
225
241
def get_usersettings (self , user ) -> list :
226
242
"""Returns all user settings for a specific user.
@@ -234,7 +250,8 @@ def get_usersettings(self, user) -> list:
234
250
list: All applicablae notification settings.
235
251
"""
236
252
methods = []
237
- for item in storage .liste :
253
+
254
+ for item in storage .methods :
238
255
if item .USER_SETTING :
239
256
new_key = f'NOTIFICATION_METHOD_{ item .METHOD_NAME .upper ()} '
240
257
@@ -250,6 +267,7 @@ def get_usersettings(self, user) -> list:
250
267
'icon' : getattr (item , 'METHOD_ICON' , '' ),
251
268
'method' : item .METHOD_NAME ,
252
269
})
270
+
253
271
return methods
254
272
255
273
@@ -352,7 +370,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
352
370
delivery_methods = kwargs .get ('delivery_methods' , None )
353
371
354
372
# Check if data is importing currently
355
- if isImportingData ():
373
+ if isImportingData () or isRebuildingData () :
356
374
return
357
375
358
376
# Resolve object reference
@@ -422,7 +440,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
422
440
423
441
# Collect possible methods
424
442
if delivery_methods is None :
425
- delivery_methods = storage .liste or []
443
+ delivery_methods = storage .methods or []
426
444
else :
427
445
delivery_methods = delivery_methods - IGNORED_NOTIFICATION_CLS
428
446
@@ -439,7 +457,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
439
457
# Set delivery flag
440
458
common .models .NotificationEntry .notify (category , obj_ref_value )
441
459
else :
442
- logger .debug ("No possible users for notification '%s'" , category )
460
+ logger .info ("No possible users for notification '%s'" , category )
443
461
444
462
445
463
def trigger_superuser_notification (plugin : PluginConfig , msg : str ):
0 commit comments