refactor to make simpler

This commit is contained in:
Matthias 2022-05-15 18:02:12 +02:00
parent 8b9c80d2a4
commit c7a2d11893
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093
2 changed files with 3 additions and 15 deletions

View File

@ -31,11 +31,7 @@ class ActionPluginView(APIView):
action_plugins = registry.with_mixin('action')
for plugin in action_plugins:
if plugin.action_name() == action:
# TODO @matmair use easier syntax once InvenTree 0.7.0 is released
plugin.init(request.user, data=data)
plugin.perform_action()
plugin.perform_action(request.user, data=data)
return Response(plugin.get_response())
# If we got to here, no matching action was found

View File

@ -15,10 +15,9 @@ class ActionMixin:
"""
MIXIN_NAME = 'Actions'
def __init__(self, user=None, data=None):
def __init__(self):
super().__init__()
self.add_mixin('action', True, __class__)
self.init(user, data)
def action_name(self):
"""
@ -31,14 +30,7 @@ class ActionMixin:
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):
def perform_action(self, user=None, data=None):
"""
Override this method to perform the action!
"""