refactor events

This commit is contained in:
Matthias 2022-05-11 13:28:59 +02:00
parent 5a139ec74b
commit 970503f424
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093
10 changed files with 39 additions and 31 deletions

View File

@ -36,7 +36,7 @@ import InvenTree.fields
import InvenTree.helpers
import InvenTree.tasks
from plugin.events import trigger_event
from plugin import trigger_event
from part import models as PartModels
from stock import models as StockModels

View File

@ -30,7 +30,7 @@ from users import models as UserModels
from part import models as PartModels
from stock import models as stock_models
from company.models import Company, SupplierPart
from plugin.events import trigger_event
from plugin import trigger_event
import InvenTree.helpers
from InvenTree.fields import InvenTreeModelMoneyField, RoundingDecimalField

View File

@ -3,16 +3,20 @@ Utility file to enable simper imports
"""
from .registry import registry
from .base.event.events import trigger_event
from .plugin import InvenTreePluginBase, IntegrationPluginBase
from .base.action.action import ActionPlugin
from .helpers import MixinNotImplementedError, MixinImplementationError
__all__ = [
'registry',
'trigger_event',
'ActionPlugin',
'IntegrationPluginBase',
'InvenTreePluginBase',
'registry',
'MixinNotImplementedError',
'MixinImplementationError',
]

View File

@ -0,0 +1,29 @@
"""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 process_event(self, event, *args, **kwargs):
"""
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):
super().__init__()
self.add_mixin('events', True, __class__)

View File

@ -238,32 +238,6 @@ class ScheduleMixin:
logger.warning("unregister_tasks failed, database not ready")
class EventMixin:
"""
Mixin that provides support for responding to triggered events.
Implementing classes must provide a "process_event" function:
"""
def process_event(self, event, *args, **kwargs):
"""
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):
super().__init__()
self.add_mixin('events', True, __class__)
class UrlsMixin:
"""
Mixin that enables custom URLs for the plugin

View File

@ -2,12 +2,13 @@
Utility class to enable simpler imports
"""
from ..base.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin, PanelMixin
from ..base.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, ScheduleMixin, UrlsMixin, NavigationMixin, PanelMixin
from common.notifications import SingleNotificationMethod, BulkNotificationMethod
from ..base.action.mixins import ActionMixin
from ..base.barcodes.mixins import BarcodeMixin
from ..base.events.mixins import EventMixin
__all__ = [
'APICallMixin',

View File

@ -38,7 +38,7 @@ import common.models
import report.models
import label.models
from plugin.events import trigger_event
from plugin import trigger_event
from InvenTree.status_codes import StockStatus, StockHistoryCode
from InvenTree.models import InvenTreeTree, InvenTreeAttachment