mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Load barcode plugins and throw test data at them
This commit is contained in:
parent
38fab9c681
commit
cb1298847e
@ -6,10 +6,14 @@ Main JSON interface views
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from .views import AjaxView
|
from .views import AjaxView
|
||||||
from .version import inventreeVersion, inventreeInstanceName
|
from .version import inventreeVersion, inventreeInstanceName
|
||||||
|
|
||||||
|
from plugins import plugins as inventree_plugins
|
||||||
|
|
||||||
|
|
||||||
class InfoView(AjaxView):
|
class InfoView(AjaxView):
|
||||||
""" Simple JSON endpoint for InvenTree information.
|
""" Simple JSON endpoint for InvenTree information.
|
||||||
@ -27,15 +31,33 @@ class InfoView(AjaxView):
|
|||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
class BarcodeScanView(AjaxView):
|
class BarcodeScanView(APIView):
|
||||||
"""
|
"""
|
||||||
Endpoint for handling barcode scan requests.
|
Endpoint for handling barcode scan requests.
|
||||||
|
|
||||||
|
Barcode data are decoded by the client application,
|
||||||
|
and sent to this endpoint (as a JSON object) for validation.
|
||||||
|
|
||||||
|
A barcode could follow the internal InvenTree barcode format,
|
||||||
|
or it could match to a third-party barcode format (e.g. Digikey).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'barcode': 'Hello world',
|
'barcode': 'Hello world',
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonResponse(data)
|
plugins = inventree_plugins.load_barcode_plugins()
|
||||||
|
|
||||||
|
for plugin in plugins:
|
||||||
|
print("Testing plugin:", plugin.PLUGIN_NAME)
|
||||||
|
if plugin().validate_barcode(request.data):
|
||||||
|
print("success!")
|
||||||
|
|
||||||
|
return Response({
|
||||||
|
'success': 'OK',
|
||||||
|
'data': data,
|
||||||
|
'post': request.data,
|
||||||
|
})
|
||||||
|
@ -83,5 +83,5 @@ class APITests(APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
def test_barcode(self):
|
def test_barcode(self):
|
||||||
|
# TODO - Complete this
|
||||||
url = reverse('api-barcode-view')
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user