Coverage for src/backend/InvenTree/plugin/base/event/mixins.py: 67%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1"""Plugin mixin class for events.""" 

2 

3from plugin import PluginMixinEnum 

4from plugin.helpers import MixinNotImplementedError 

5 

6 

7class EventMixin: 

8 """Mixin that provides support for responding to triggered events. 

9 

10 Implementing classes must provide a "process_event" function: 

11 """ 

12 

13 def wants_process_event(self, event: str) -> bool: 

14 """Function to subscribe to events. 

15 

16 Return true if you're interested in the given event, false if not. 

17 """ 

18 # Default implementation always returns true (backwards compatibility) 

19 return True 

20 

21 def process_event(self, event: str, *args, **kwargs) -> None: 

22 """Function to handle events. 

23 

24 Must be overridden by plugin 

25 """ 

26 # Default implementation does not do anything 

27 raise MixinNotImplementedError 

28 

29 class MixinMeta: 

30 """Meta options for this mixin.""" 

31 

32 MIXIN_NAME = 'Events' 

33 

34 def __init__(self): 

35 """Register the mixin.""" 

36 super().__init__() 

37 self.add_mixin(PluginMixinEnum.EVENTS, True, __class__)