Merge pull request #409 from SchrodingersGat/info-endpoint

Add a simple endpoint with server information
This commit is contained in:
Oliver 2019-06-25 00:41:01 +10:00 committed by GitHub
commit ea44f28bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 rest_framework.documentation import include_docs_urls
from .views import IndexView, SearchView, SettingsView, EditUserView, SetPasswordView from .views import IndexView, SearchView, SettingsView, EditUserView, SetPasswordView
from .views import InfoView
from users.urls import user_urls from users.urls import user_urls
@ -45,6 +46,9 @@ apipatterns = [
# User URLs # User URLs
url(r'^user/', include(user_urls)), url(r'^user/', include(user_urls)),
# InvenTree information endpoint
url(r'^$', InfoView.as_view(), name='inventree-info'),
] ]
urlpatterns = [ urlpatterns = [

View File

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