mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor to make simpler
This commit is contained in:
parent
8b9c80d2a4
commit
c7a2d11893
@ -31,11 +31,7 @@ class ActionPluginView(APIView):
|
|||||||
action_plugins = registry.with_mixin('action')
|
action_plugins = registry.with_mixin('action')
|
||||||
for plugin in action_plugins:
|
for plugin in action_plugins:
|
||||||
if plugin.action_name() == action:
|
if plugin.action_name() == action:
|
||||||
# TODO @matmair use easier syntax once InvenTree 0.7.0 is released
|
plugin.perform_action(request.user, data=data)
|
||||||
plugin.init(request.user, data=data)
|
|
||||||
|
|
||||||
plugin.perform_action()
|
|
||||||
|
|
||||||
return Response(plugin.get_response())
|
return Response(plugin.get_response())
|
||||||
|
|
||||||
# If we got to here, no matching action was found
|
# If we got to here, no matching action was found
|
||||||
|
@ -15,10 +15,9 @@ class ActionMixin:
|
|||||||
"""
|
"""
|
||||||
MIXIN_NAME = 'Actions'
|
MIXIN_NAME = 'Actions'
|
||||||
|
|
||||||
def __init__(self, user=None, data=None):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_mixin('action', True, __class__)
|
self.add_mixin('action', True, __class__)
|
||||||
self.init(user, data)
|
|
||||||
|
|
||||||
def action_name(self):
|
def action_name(self):
|
||||||
"""
|
"""
|
||||||
@ -31,14 +30,7 @@ class ActionMixin:
|
|||||||
return self.ACTION_NAME
|
return self.ACTION_NAME
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def init(self, user, data=None):
|
def perform_action(self, user=None, 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!
|
Override this method to perform the action!
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user