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)