2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

move action

This commit is contained in:
Matthias
2022-05-11 12:38:14 +02:00
parent 308dd53c35
commit 0d89959d49
6 changed files with 5 additions and 5 deletions

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""Class for ActionPlugin"""
import logging
import warnings
from plugin.base.action.mixins import ActionMixin
import plugin.integration
logger = logging.getLogger("inventree")
class ActionPlugin(ActionMixin, plugin.integration.IntegrationPluginBase):
"""
Legacy action definition - will be replaced
Please use the new Integration Plugin API and the Action mixin
"""
# TODO @matmair remove this with InvenTree 0.7.0
def __init__(self, user=None, data=None):
warnings.warn("using the ActionPlugin is depreceated", DeprecationWarning)
super().__init__()
self.init(user, data)

View File

@ -0,0 +1,68 @@
"""
Plugin mixin classes for action plugin
"""
class ActionMixin:
"""
Mixin that enables custom actions
"""
ACTION_NAME = ""
class MixinMeta:
"""
meta options for this mixin
"""
MIXIN_NAME = 'Actions'
def __init__(self):
super().__init__()
self.add_mixin('action', True, __class__)
def action_name(self):
"""
Action name for this plugin.
If the ACTION_NAME parameter is empty,
uses the PLUGIN_NAME instead.
"""
if self.ACTION_NAME:
return self.ACTION_NAME
return self.name
def init(self, user, data=None):
"""
An action plugin takes a user reference, and an optional dataset (dict)
"""
self.user = user
self.data = data
def perform_action(self):
"""
Override this method to perform the action!
"""
def get_result(self):
"""
Result of the action?
"""
# Re-implement this for cutsom actions
return False
def get_info(self):
"""
Extra info? Can be a string / dict / etc
"""
return None
def get_response(self):
"""
Return a response. Default implementation is a simple response
which can be overridden.
"""
return {
"action": self.action_name(),
"result": self.get_result(),
"info": self.get_info(),
}