Add a simple endpoint with server information

This commit is contained in:
Oliver Walters 2019-06-24 23:51:46 +10:00
parent 5d0369958f
commit c7877c67ff
2 changed files with 20 additions and 0 deletions

View File

@ -31,6 +31,7 @@ from django.views.generic.base import RedirectView
from rest_framework.documentation import include_docs_urls
from .views import IndexView, SearchView, SettingsView, EditUserView, SetPasswordView
from .views import InfoView
from users.urls import user_urls
@ -45,6 +46,9 @@ apipatterns = [
# User URLs
url(r'^user/', include(user_urls)),
# InvenTree information endpoint
url(r'^$', InfoView.as_view(), name='inventree-info'),
]
urlpatterns = [

View File

@ -19,6 +19,7 @@ from part.models import Part
from .forms import DeleteForm, EditUserForm, SetPasswordForm
from .helpers import str2bool
from .version import inventreeVersion
from rest_framework import views
@ -392,6 +393,21 @@ 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()
}
return JsonResponse(data)
class EditUserView(AjaxUpdateView):
""" View for editing user information """