From 24fb68bd3e1ccfea2ee398c9e18afb01eb340fee Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 29 May 2022 01:28:06 +0200 Subject: [PATCH] Make API code cleaner --- InvenTree/plugin/api.py | 14 +------------- InvenTree/plugin/serializers.py | 3 ++- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/InvenTree/plugin/api.py b/InvenTree/plugin/api.py index 2f4bd2caa7..00cab46dc3 100644 --- a/InvenTree/plugin/api.py +++ b/InvenTree/plugin/api.py @@ -4,9 +4,8 @@ from django.conf import settings from django.urls import include, re_path 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.response import Response import plugin.serializers as PluginSerializers from common.api import GlobalSettingsPermissions @@ -99,17 +98,6 @@ class PluginInstall(generics.CreateAPIView): queryset = PluginConfig.objects.none() 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): """List endpoint for all plugin related settings. diff --git a/InvenTree/plugin/serializers.py b/InvenTree/plugin/serializers.py index 857d5504dc..a29ca56046 100644 --- a/InvenTree/plugin/serializers.py +++ b/InvenTree/plugin/serializers.py @@ -144,7 +144,8 @@ class PluginConfigInstallSerializer(serializers.Serializer): 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') - return ret + # Set result as serializer data -> this will be returned + self.data = ret class PluginSettingSerializer(GenericReferencedSettingSerializer):