Make API code cleaner

This commit is contained in:
Matthias 2022-05-29 01:28:06 +02:00
parent c24882bf66
commit 24fb68bd3e
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093
2 changed files with 3 additions and 14 deletions

View File

@ -4,9 +4,8 @@ from django.conf import settings
from django.urls import include, re_path from django.urls import include, re_path
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, generics, permissions, status from rest_framework import filters, generics, permissions
from rest_framework.exceptions import NotFound from rest_framework.exceptions import NotFound
from rest_framework.response import Response
import plugin.serializers as PluginSerializers import plugin.serializers as PluginSerializers
from common.api import GlobalSettingsPermissions from common.api import GlobalSettingsPermissions
@ -99,17 +98,6 @@ class PluginInstall(generics.CreateAPIView):
queryset = PluginConfig.objects.none() queryset = PluginConfig.objects.none()
serializer_class = PluginSerializers.PluginConfigInstallSerializer serializer_class = PluginSerializers.PluginConfigInstallSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
result = self.perform_create(serializer)
result['input'] = serializer.data
headers = self.get_success_headers(serializer.data)
return Response(result, status=status.HTTP_201_CREATED, headers=headers)
def perform_create(self, serializer):
return serializer.save()
class PluginSettingList(generics.ListAPIView): class PluginSettingList(generics.ListAPIView):
"""List endpoint for all plugin related settings. """List endpoint for all plugin related settings.

View File

@ -144,7 +144,8 @@ class PluginConfigInstallSerializer(serializers.Serializer):
with open(settings.PLUGIN_FILE, "a") as plugin_file: with open(settings.PLUGIN_FILE, "a") as plugin_file:
plugin_file.write(f'{" ".join(install_name)} # Installed {timezone.now()} by {str(self.context["request"].user)}\n') plugin_file.write(f'{" ".join(install_name)} # Installed {timezone.now()} by {str(self.context["request"].user)}\n')
return ret # Set result as serializer data -> this will be returned
self.data = ret
class PluginSettingSerializer(GenericReferencedSettingSerializer): class PluginSettingSerializer(GenericReferencedSettingSerializer):