mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
- Instead of registry.plugins.get() - get_plugin checks registry hash - performs registry reload if necessary (cherry picked from commit e9c6dd82737832052cc647b4161658d75d6b66fd) Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
37 lines
1023 B
Python
37 lines
1023 B
Python
"""Plugin mixin class for events."""
|
|
|
|
from plugin.helpers import MixinNotImplementedError
|
|
|
|
|
|
class EventMixin:
|
|
"""Mixin that provides support for responding to triggered events.
|
|
|
|
Implementing classes must provide a "process_event" function:
|
|
"""
|
|
|
|
def wants_process_event(self, event: str) -> bool:
|
|
"""Function to subscribe to events.
|
|
|
|
Return true if you're interested in the given event, false if not.
|
|
"""
|
|
# Default implementation always returns true (backwards compatibility)
|
|
return True
|
|
|
|
def process_event(self, event: str, *args, **kwargs) -> None:
|
|
"""Function to handle events.
|
|
|
|
Must be overridden by plugin
|
|
"""
|
|
# Default implementation does not do anything
|
|
raise MixinNotImplementedError
|
|
|
|
class MixinMeta:
|
|
"""Meta options for this mixin."""
|
|
|
|
MIXIN_NAME = 'Events'
|
|
|
|
def __init__(self):
|
|
"""Register the mixin."""
|
|
super().__init__()
|
|
self.add_mixin('events', True, __class__)
|