mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Further barcode work
- Simplify InvenTree barcode format - Create base-clas for plugin
This commit is contained in:
@ -1,19 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import plugins.plugin as plugin
|
||||
|
||||
class BarcodePlugin:
|
||||
|
||||
class BarcodePlugin(plugin.InvenTreePlugin):
|
||||
"""
|
||||
The BarcodePlugin class is the base class for any barcode plugin.
|
||||
"""
|
||||
|
||||
# Override this for each actual plugin
|
||||
PLUGIN_NAME = ''
|
||||
|
||||
def validate_barcode(self, barcode_data):
|
||||
"""
|
||||
Default implementation returns False
|
||||
"""
|
||||
return False
|
||||
|
||||
def decode_barcode(self, barcode_data):
|
||||
"""
|
||||
Decode the barcode, and craft a response
|
||||
"""
|
||||
|
||||
return None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
plugin.InvenTreePlugin.__init__(self)
|
||||
|
@ -8,7 +8,24 @@ class InvenTreeBarcodePlugin(barcode.BarcodePlugin):
|
||||
PLUGIN_NAME = "InvenTreeBarcodePlugin"
|
||||
|
||||
def validate_barcode(self, barcode_data):
|
||||
"""
|
||||
An "InvenTree" barcode must include the following tags:
|
||||
|
||||
print("testing")
|
||||
{
|
||||
'tool': 'InvenTree',
|
||||
'version': <anything>
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
for key in ['tool', 'version']:
|
||||
if key not in barcode_data.keys():
|
||||
return False
|
||||
|
||||
if not barcode_data['tool'] == 'InvenTree':
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def decode_barcode(self, barcode_data):
|
||||
pass
|
||||
|
16
InvenTree/plugins/plugin.py
Normal file
16
InvenTree/plugins/plugin.py
Normal file
@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class InvenTreePlugin():
|
||||
"""
|
||||
Base class for a Barcode plugin
|
||||
"""
|
||||
|
||||
# Override the plugin name for each concrete plugin instance
|
||||
PLUGIN_NAME = ''
|
||||
|
||||
def get_name(self):
|
||||
return self.PLUGIN_NAME
|
||||
|
||||
def __init__(self):
|
||||
pass
|
@ -52,4 +52,12 @@ def load_barcode_plugins():
|
||||
Return a list of all registered barcode plugins
|
||||
"""
|
||||
|
||||
return get_plugins(barcode, BarcodePlugin)
|
||||
plugins = get_plugins(barcode, BarcodePlugin)
|
||||
|
||||
if len(plugins) > 0:
|
||||
print("Discovered {n} barcode plugins:".format(n=len(plugins)))
|
||||
|
||||
for bp in plugins:
|
||||
print(" - {bp}".format(bp=bp.PLUGIN_NAME))
|
||||
|
||||
return plugins
|
||||
|
Reference in New Issue
Block a user