mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
refactor events
This commit is contained in:
parent
5a139ec74b
commit
970503f424
@ -36,7 +36,7 @@ import InvenTree.fields
|
|||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import InvenTree.tasks
|
import InvenTree.tasks
|
||||||
|
|
||||||
from plugin.events import trigger_event
|
from plugin import trigger_event
|
||||||
|
|
||||||
from part import models as PartModels
|
from part import models as PartModels
|
||||||
from stock import models as StockModels
|
from stock import models as StockModels
|
||||||
|
@ -30,7 +30,7 @@ from users import models as UserModels
|
|||||||
from part import models as PartModels
|
from part import models as PartModels
|
||||||
from stock import models as stock_models
|
from stock import models as stock_models
|
||||||
from company.models import Company, SupplierPart
|
from company.models import Company, SupplierPart
|
||||||
from plugin.events import trigger_event
|
from plugin import trigger_event
|
||||||
|
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
from InvenTree.fields import InvenTreeModelMoneyField, RoundingDecimalField
|
from InvenTree.fields import InvenTreeModelMoneyField, RoundingDecimalField
|
||||||
|
@ -3,16 +3,20 @@ Utility file to enable simper imports
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from .registry import registry
|
from .registry import registry
|
||||||
|
from .base.event.events import trigger_event
|
||||||
|
|
||||||
from .plugin import InvenTreePluginBase, IntegrationPluginBase
|
from .plugin import InvenTreePluginBase, IntegrationPluginBase
|
||||||
from .base.action.action import ActionPlugin
|
from .base.action.action import ActionPlugin
|
||||||
|
|
||||||
from .helpers import MixinNotImplementedError, MixinImplementationError
|
from .helpers import MixinNotImplementedError, MixinImplementationError
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
'registry',
|
||||||
|
'trigger_event',
|
||||||
|
|
||||||
'ActionPlugin',
|
'ActionPlugin',
|
||||||
'IntegrationPluginBase',
|
'IntegrationPluginBase',
|
||||||
'InvenTreePluginBase',
|
'InvenTreePluginBase',
|
||||||
'registry',
|
|
||||||
'MixinNotImplementedError',
|
'MixinNotImplementedError',
|
||||||
'MixinImplementationError',
|
'MixinImplementationError',
|
||||||
]
|
]
|
||||||
|
29
InvenTree/plugin/base/event/mixins.py
Normal file
29
InvenTree/plugin/base/event/mixins.py
Normal 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__)
|
@ -238,32 +238,6 @@ class ScheduleMixin:
|
|||||||
logger.warning("unregister_tasks failed, database not ready")
|
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:
|
class UrlsMixin:
|
||||||
"""
|
"""
|
||||||
Mixin that enables custom URLs for the plugin
|
Mixin that enables custom URLs for the plugin
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
Utility class to enable simpler imports
|
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 common.notifications import SingleNotificationMethod, BulkNotificationMethod
|
||||||
|
|
||||||
from ..base.action.mixins import ActionMixin
|
from ..base.action.mixins import ActionMixin
|
||||||
from ..base.barcodes.mixins import BarcodeMixin
|
from ..base.barcodes.mixins import BarcodeMixin
|
||||||
|
from ..base.events.mixins import EventMixin
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'APICallMixin',
|
'APICallMixin',
|
||||||
|
0
InvenTree/plugin/samples/event/__init__.py
Normal file
0
InvenTree/plugin/samples/event/__init__.py
Normal file
@ -38,7 +38,7 @@ import common.models
|
|||||||
import report.models
|
import report.models
|
||||||
import label.models
|
import label.models
|
||||||
|
|
||||||
from plugin.events import trigger_event
|
from plugin import trigger_event
|
||||||
|
|
||||||
from InvenTree.status_codes import StockStatus, StockHistoryCode
|
from InvenTree.status_codes import StockStatus, StockHistoryCode
|
||||||
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
|
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user