mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
use new loading mechanism for barcodes too
This commit is contained in:
parent
13ff94b6b2
commit
4fc3e85a53
@ -13,7 +13,7 @@ from stock.models import StockItem
|
||||
from stock.serializers import StockItemSerializer
|
||||
|
||||
from barcodes.barcode import hash_barcode
|
||||
from plugin.plugins import load_barcode_plugins
|
||||
from plugin import plugin_registry
|
||||
|
||||
|
||||
class BarcodeScan(APIView):
|
||||
@ -53,7 +53,7 @@ class BarcodeScan(APIView):
|
||||
if 'barcode' not in data:
|
||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
||||
|
||||
plugins = load_barcode_plugins()
|
||||
plugins = plugin_registry.with_mixin('barcode')
|
||||
|
||||
barcode_data = data.get('barcode')
|
||||
|
||||
@ -160,7 +160,7 @@ class BarcodeAssign(APIView):
|
||||
except (ValueError, StockItem.DoesNotExist):
|
||||
raise ValidationError({'stockitem': _('No matching stock item found')})
|
||||
|
||||
plugins = load_barcode_plugins()
|
||||
plugins = plugin_registry.with_mixin('barcode')
|
||||
|
||||
plugin = None
|
||||
|
||||
|
@ -4,14 +4,10 @@
|
||||
import inspect
|
||||
import importlib
|
||||
import pkgutil
|
||||
import logging
|
||||
|
||||
from django.core.exceptions import AppRegistryNotReady
|
||||
|
||||
|
||||
logger = logging.getLogger("inventree")
|
||||
|
||||
|
||||
def iter_namespace(pkg):
|
||||
"""get all modules in a package"""
|
||||
return pkgutil.iter_modules(pkg.__path__, pkg.__name__ + ".")
|
||||
@ -70,34 +66,3 @@ def get_plugins(pkg, baseclass, recursive: bool = False):
|
||||
plugins.append(plugin)
|
||||
|
||||
return plugins
|
||||
|
||||
|
||||
def load_plugins(name: str, cls, module):
|
||||
"""general function to load a plugin class
|
||||
|
||||
:param name: name of the plugin for logs
|
||||
:type name: str
|
||||
:param module: module from which the plugins should be loaded
|
||||
:return: class of the to-be-loaded plugin
|
||||
"""
|
||||
logger.debug("Loading %s plugins", name)
|
||||
|
||||
plugins = get_plugins(module, cls)
|
||||
|
||||
if len(plugins) > 0:
|
||||
logger.info("Discovered %i %s plugins:", len(plugins), name)
|
||||
|
||||
for plugin in plugins:
|
||||
logger.debug(" - %s", plugin.PLUGIN_NAME)
|
||||
|
||||
return plugins
|
||||
|
||||
|
||||
def load_barcode_plugins():
|
||||
"""
|
||||
Return a list of all registered barcode plugins
|
||||
"""
|
||||
from barcodes import plugins as BarcodePlugins
|
||||
from barcodes.barcode import BarcodePlugin
|
||||
|
||||
return load_plugins('barcode', BarcodePlugin, BarcodePlugins)
|
||||
|
@ -34,18 +34,6 @@ class InvenTreePluginTests(TestCase):
|
||||
self.assertEqual(self.named_plugin.plugin_name(), 'abc123')
|
||||
|
||||
|
||||
class PluginIntegrationTests(TestCase):
|
||||
""" Tests for general plugin functions """
|
||||
|
||||
def test_plugin_loading(self):
|
||||
"""check if plugins load as expected"""
|
||||
# plugin_names_barcode = [a().plugin_name() for a in load_barcode_plugins()] # TODO refactor barcode plugin to support standard loading
|
||||
|
||||
# self.assertEqual(plugin_names_barcode, '')
|
||||
|
||||
# TODO remove test once loading is moved
|
||||
|
||||
|
||||
class PluginTagTests(TestCase):
|
||||
""" Tests for the plugin extras """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user