diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py new file mode 100644 index 0000000000..e242f07e0f --- /dev/null +++ b/InvenTree/InvenTree/api.py @@ -0,0 +1,41 @@ +""" +Main JSON interface views +""" + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.http import JsonResponse + +from .views import AjaxView +from .version import inventreeVersion, inventreeInstanceName + + +class InfoView(AjaxView): + """ Simple JSON endpoint for InvenTree information. + Use to confirm that the server is running, etc. + """ + + def get(self, request, *args, **kwargs): + + data = { + 'server': 'InvenTree', + 'version': inventreeVersion(), + 'instance': inventreeInstanceName(), + } + + return JsonResponse(data) + + +class BarcodeScanView(AjaxView): + """ + Endpoint for handling barcode scan requests. + """ + + def get(self, request, *args, **kwargs): + + data = { + 'barcode': 'Hello world', + } + + return JsonResponse(data) diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py index 0bb36db59f..0851815cfd 100644 --- a/InvenTree/InvenTree/test_api.py +++ b/InvenTree/InvenTree/test_api.py @@ -27,6 +27,18 @@ class APITests(APITestCase): User = get_user_model() User.objects.create_user(self.username, 'user@email.com', self.password) + def test_info_view(self): + """ + Test that we can read the 'info-view' endpoint. + """ + + url = reverse('api-inventree-info') + + response = self.client.get(url, format='json') + + print(response) + print(dir(response)) + def test_get_token_fail(self): """ Ensure that an invalid user cannot get a token """ @@ -65,3 +77,7 @@ class APITests(APITestCase): response = self.client.get(part_url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_barcode(self): + + url = reverse('api-barcode-view') \ No newline at end of file diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index fd36fa9112..1d1fabc795 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -35,7 +35,8 @@ from rest_framework.documentation import include_docs_urls from .views import IndexView, SearchView, DatabaseStatsView from .views import SettingsView, EditUserView, SetPasswordView -from .views import InfoView + +from .api import InfoView, BarcodeScanView from users.urls import user_urls @@ -53,8 +54,11 @@ apipatterns = [ # User URLs url(r'^user/', include(user_urls)), + # Barcode scanning endpoint + url(r'^barcode/', BarcodeScanView.as_view(), name='api-barcode-scan'), + # InvenTree information endpoint - url(r'^$', InfoView.as_view(), name='inventree-info'), + url(r'^$', InfoView.as_view(), name='api-inventree-info'), ] settings_urls = [ diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 59833d3e6b..943a18d35c 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -22,7 +22,6 @@ from common.models import InvenTreeSetting from .forms import DeleteForm, EditUserForm, SetPasswordForm from .helpers import str2bool -from .version import inventreeVersion, inventreeInstanceName from rest_framework import views @@ -416,22 +415,6 @@ class AjaxDeleteView(AjaxMixin, UpdateView): return self.renderJsonResponse(request, form, data=data, context=context) -class InfoView(AjaxView): - """ Simple JSON endpoint for InvenTree information. - Use to confirm that the server is running, etc. - """ - - def get(self, request, *args, **kwargs): - - data = { - 'server': 'InvenTree', - 'version': inventreeVersion(), - 'instance': inventreeInstanceName(), - } - - return JsonResponse(data) - - class EditUserView(AjaxUpdateView): """ View for editing user information """