From bd8a6c4994fe414f78149530f92f0f3d0d88092a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 21 Sep 2021 15:48:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Merge=20`version`=20route=20into?= =?UTF-8?q?=20`instance`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/core/models.py | 7 +++++++ backend/sophon/core/serializers.py | 2 +- backend/sophon/core/urls.py | 1 - backend/sophon/core/views.py | 16 +++------------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/backend/sophon/core/models.py b/backend/sophon/core/models.py index fcc3e40..20b6b90 100644 --- a/backend/sophon/core/models.py +++ b/backend/sophon/core/models.py @@ -6,6 +6,8 @@ properly. from __future__ import annotations import typing import abc + +import pkg_resources from django.db import models from django.contrib.auth.models import User from rest_framework.serializers import ModelSerializer @@ -203,12 +205,17 @@ class SophonInstanceDetails(SophonModel): max_length=32, ) + @property + def version(self) -> str: + return pkg_resources.get_distribution("sophon").version + @classmethod def get_fields(cls) -> set[str]: return { "name", "description", "theme", + "version", } @classmethod diff --git a/backend/sophon/core/serializers.py b/backend/sophon/core/serializers.py index 8e05381..089a5cd 100644 --- a/backend/sophon/core/serializers.py +++ b/backend/sophon/core/serializers.py @@ -1,5 +1,5 @@ from django.contrib.auth.models import User -from rest_framework.serializers import Serializer, ModelSerializer +from rest_framework.serializers import Serializer, ModelSerializer, CharField class NoneSerializer(Serializer): diff --git a/backend/sophon/core/urls.py b/backend/sophon/core/urls.py index 477bf4d..2ac0088 100644 --- a/backend/sophon/core/urls.py +++ b/backend/sophon/core/urls.py @@ -11,6 +11,5 @@ router.register("users", views.UserViewSet, basename="user") urlpatterns = [ path("", include(router.urls)), - path("version", views.VersionView.as_view()), path("instance", views.SophonInstanceDetailsView.as_view()), ] diff --git a/backend/sophon/core/views.py b/backend/sophon/core/views.py index 05bf32f..2203ac6 100644 --- a/backend/sophon/core/views.py +++ b/backend/sophon/core/views.py @@ -279,17 +279,6 @@ class SophonGroupViewSet(WriteSophonViewSet, metaclass=abc.ABCMeta): 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=s.HTTP_200_OK) - - class SophonInstanceDetailsView(APIView): """ Get the details of this Sophon instance. @@ -298,6 +287,7 @@ class SophonInstanceDetailsView(APIView): # noinspection PyMethodMayBeStatic,PyUnusedLocal def get(self, request, format=None): details = models.SophonInstanceDetails.objects.get() - Serializer = details.get_view_serializer() - serializer = Serializer(instance=details) + # noinspection PyPep8Naming + ViewSerializer = details.get_view_serializer() + serializer = ViewSerializer(instance=details) return Response(serializer.data, status=s.HTTP_200_OK)