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
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Plugin mixin class for events."""
3from plugin import PluginMixinEnum
4from plugin.helpers import MixinNotImplementedError
7class EventMixin:
8 """Mixin that provides support for responding to triggered events.
10 Implementing classes must provide a "process_event" function:
11 """
13 def wants_process_event(self, event: str) -> bool:
14 """Function to subscribe to events.
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
21 def process_event(self, event: str, *args, **kwargs) -> None:
22 """Function to handle events.
24 Must be overridden by plugin
25 """
26 # Default implementation does not do anything
27 raise MixinNotImplementedError
29 class MixinMeta:
30 """Meta options for this mixin."""
32 MIXIN_NAME = 'Events'
34 def __init__(self):
35 """Register the mixin."""
36 super().__init__()
37 self.add_mixin(PluginMixinEnum.EVENTS, True, __class__)