From 1b842770bc4e6f89c2ed7b8bd0e590dbfdf60fe9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 14 Sep 2021 03:28:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20the=20`/api/core/version`=20v?= =?UTF-8?q?iew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/inspectionProfiles/Project_Default.xml | 7 +++++++ backend/sophon/core/urls.py | 1 + backend/sophon/core/views.py | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 46c59b2..637eb1a 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -35,6 +35,13 @@ + + + diff --git a/backend/sophon/core/urls.py b/backend/sophon/core/urls.py index 63b764d..b832935 100644 --- a/backend/sophon/core/urls.py +++ b/backend/sophon/core/urls.py @@ -10,4 +10,5 @@ router.register("groups", views.ResearchGroupViewSet, basename="research-group") urlpatterns = [ path("", include(router.urls)), + path("version", views.VersionView.as_view()) ] diff --git a/backend/sophon/core/views.py b/backend/sophon/core/views.py index 9cadeae..1d4ed9d 100644 --- a/backend/sophon/core/views.py +++ b/backend/sophon/core/views.py @@ -2,6 +2,8 @@ import abc import typing as t import deprecation +import pkg_resources +from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet from rest_framework.response import Response from rest_framework.serializers import Serializer @@ -245,3 +247,14 @@ class SophonGroupViewSet(SophonViewSet, metaclass=abc.ABCMeta): return permissions.Edit, else: return permissions.AllowAny, + + +class VersionView(APIView): + """ + Get the Sophon server version. + """ + + # noinspection PyMethodMayBeStatic,PyUnusedLocal + def get(self, request, format=None): + version = pkg_resources.get_distribution("sophon").version + return Response(version, status=status.HTTP_200_OK)