1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 14:54:22 +00:00

🔧 Merge version route into instance

This commit is contained in:
Steffo 2021-09-21 15:48:16 +02:00
parent 6d172a5a44
commit 4398427865
4 changed files with 11 additions and 15 deletions

View file

@ -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

View file

@ -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):

View file

@ -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()),
]

View file

@ -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)