mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
remove old loading mechanism
This commit is contained in:
parent
8088bf28fe
commit
bcb0f62e42
@ -5,8 +5,6 @@ Main JSON interface views
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
|
||||||
@ -21,15 +19,7 @@ from .views import AjaxView
|
|||||||
from .version import inventreeVersion, inventreeApiVersion, inventreeInstanceName
|
from .version import inventreeVersion, inventreeApiVersion, inventreeInstanceName
|
||||||
from .status import is_worker_running
|
from .status import is_worker_running
|
||||||
|
|
||||||
from plugin.plugins import load_action_plugins
|
from plugin import plugin_registry
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger("inventree")
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Loading action plugins...")
|
|
||||||
action_plugins = load_action_plugins()
|
|
||||||
|
|
||||||
|
|
||||||
class InfoView(AjaxView):
|
class InfoView(AjaxView):
|
||||||
""" Simple JSON endpoint for InvenTree information.
|
""" Simple JSON endpoint for InvenTree information.
|
||||||
@ -110,10 +100,11 @@ class ActionPluginView(APIView):
|
|||||||
'error': _("No action specified")
|
'error': _("No action specified")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
action_plugins = plugin_registry.with_mixin('action')
|
||||||
for plugin_class in action_plugins:
|
for plugin_class in action_plugins:
|
||||||
if plugin_class.action_name() == action:
|
if plugin_class.action_name() == action:
|
||||||
|
# TODO @matmair use easier syntax once InvenTree 0.7.0 is released
|
||||||
plugin = plugin_class(request.user, data=data)
|
plugin = plugin_class.init(request.user, data=data)
|
||||||
|
|
||||||
plugin.perform_action()
|
plugin.perform_action()
|
||||||
|
|
||||||
|
@ -8,10 +8,6 @@ import logging
|
|||||||
|
|
||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
|
|
||||||
# Action plugins
|
|
||||||
import plugin.builtin.action as action
|
|
||||||
from plugin.action import ActionPlugin
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger("inventree")
|
logger = logging.getLogger("inventree")
|
||||||
|
|
||||||
@ -97,13 +93,6 @@ def load_plugins(name: str, cls, module):
|
|||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
|
|
||||||
def load_action_plugins():
|
|
||||||
"""
|
|
||||||
Return a list of all registered action plugins
|
|
||||||
"""
|
|
||||||
return load_plugins('action', ActionPlugin, action)
|
|
||||||
|
|
||||||
|
|
||||||
def load_barcode_plugins():
|
def load_barcode_plugins():
|
||||||
"""
|
"""
|
||||||
Return a list of all registered barcode plugins
|
Return a list of all registered barcode plugins
|
||||||
|
@ -183,7 +183,17 @@ class PluginsRegistry:
|
|||||||
# Log collected plugins
|
# Log collected plugins
|
||||||
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
||||||
logger.info(", ".join([a.__module__ for a in self.plugin_modules]))
|
logger.info(", ".join([a.__module__ for a in self.plugin_modules]))
|
||||||
|
def with_mixin(self, mixin: str):
|
||||||
|
"""
|
||||||
|
Returns reference to all plugins that have a specified mixin enabled
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for plugin in self.plugins.items():
|
||||||
|
if plugin.mixin_enabled(mixin):
|
||||||
|
result.append(plugin)
|
||||||
|
|
||||||
|
return result
|
||||||
def _init_plugins(self, disabled=None):
|
def _init_plugins(self, disabled=None):
|
||||||
"""
|
"""
|
||||||
Initialise all found plugins
|
Initialise all found plugins
|
||||||
|
Loading…
x
Reference in New Issue
Block a user