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:
parent
6d172a5a44
commit
4398427865
4 changed files with 11 additions and 15 deletions
|
@ -6,6 +6,8 @@ properly.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import typing
|
import typing
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
import pkg_resources
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
@ -203,12 +205,17 @@ class SophonInstanceDetails(SophonModel):
|
||||||
max_length=32,
|
max_length=32,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version(self) -> str:
|
||||||
|
return pkg_resources.get_distribution("sophon").version
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> set[str]:
|
def get_fields(cls) -> set[str]:
|
||||||
return {
|
return {
|
||||||
"name",
|
"name",
|
||||||
"description",
|
"description",
|
||||||
"theme",
|
"theme",
|
||||||
|
"version",
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib.auth.models import User
|
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):
|
class NoneSerializer(Serializer):
|
||||||
|
|
|
@ -11,6 +11,5 @@ router.register("users", views.UserViewSet, basename="user")
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(router.urls)),
|
path("", include(router.urls)),
|
||||||
path("version", views.VersionView.as_view()),
|
|
||||||
path("instance", views.SophonInstanceDetailsView.as_view()),
|
path("instance", views.SophonInstanceDetailsView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -279,17 +279,6 @@ class SophonGroupViewSet(WriteSophonViewSet, metaclass=abc.ABCMeta):
|
||||||
return permissions.AllowAny,
|
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):
|
class SophonInstanceDetailsView(APIView):
|
||||||
"""
|
"""
|
||||||
Get the details of this Sophon instance.
|
Get the details of this Sophon instance.
|
||||||
|
@ -298,6 +287,7 @@ class SophonInstanceDetailsView(APIView):
|
||||||
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
details = models.SophonInstanceDetails.objects.get()
|
details = models.SophonInstanceDetails.objects.get()
|
||||||
Serializer = details.get_view_serializer()
|
# noinspection PyPep8Naming
|
||||||
serializer = Serializer(instance=details)
|
ViewSerializer = details.get_view_serializer()
|
||||||
|
serializer = ViewSerializer(instance=details)
|
||||||
return Response(serializer.data, status=s.HTTP_200_OK)
|
return Response(serializer.data, status=s.HTTP_200_OK)
|
||||||
|
|
Loading…
Reference in a new issue