Coverage for src/backend/InvenTree/plugin/base/action/mixins.py: 52%
19 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 classes for action plugin."""
3from plugin import PluginMixinEnum
6class ActionMixin:
7 """Mixin that enables custom actions."""
9 ACTION_NAME = ''
11 class MixinMeta:
12 """Meta options for this mixin."""
14 MIXIN_NAME = 'Actions'
16 def __init__(self):
17 """Register mixin."""
18 super().__init__()
19 self.add_mixin(PluginMixinEnum.ACTION, True, __class__)
21 def action_name(self):
22 """Action name for this plugin.
24 If the ACTION_NAME parameter is empty,
25 uses the NAME instead.
26 """
27 if self.ACTION_NAME:
28 return self.ACTION_NAME
29 return self.name
31 def perform_action(self, user=None, data=None):
32 """Override this method to perform the action!"""
34 def get_result(self, user=None, data=None):
35 """Result of the action?"""
36 # Re-implement this for cutsom actions
37 return False
39 def get_info(self, user=None, data=None):
40 """Extra info?
42 Can be a string / dict / etc
43 """
44 return None
46 def get_response(self, user=None, data=None):
47 """Return a response.
49 Default implementation is a simple response which can be overridden.
50 """
51 return {
52 'action': self.action_name(),
53 'result': self.get_result(user, data),
54 'info': self.get_info(user, data),
55 }