Skip to content
Snippets Groups Projects

Refactor update creation api

Merged Samuel GAIST requested to merge refactor_update_creation_api into master
All threads resolved!
1 file
+ 5
9
Compare changes
  • Side-by-side
  • Inline
@@ -34,9 +34,8 @@ from django.core.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework import serializers
from rest_framework.exceptions import PermissionDenied, ParseError
from rest_framework import exceptions as drf_exceptions
from ..common.responses import BadRequestResponse
from ..common.api import (
CheckContributionNameView,
ShareView,
@@ -118,13 +117,10 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
model = Toolchain
serializer_class = FullToolchainSerializer
def put(self, request, author_name, object_name, version=None):
if version is None:
return BadRequestResponse("A version number must be provided")
def put(self, request, author_name, object_name, version):
try:
data = request.data
except ParseError as e:
except drf_exceptions.ParseError as e:
raise serializers.ValidationError({"data": str(e)})
else:
if not data:
@@ -229,7 +225,7 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
# Check that the object can still be modified (if applicable, the
# documentation can always be modified)
if declaration is not None and not dbtoolchain.modifiable():
raise PermissionDenied(
raise drf_exceptions.PermissionDenied(
"The {} isn't modifiable anymore (either shared with someone else, or needed by an attestation)".format(
dbtoolchain.model_name()
)
@@ -263,7 +259,7 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView)
try:
dbtoolchain.save()
except Exception as e:
return BadRequestResponse(str(e))
raise drf_exceptions.APIException(str(e))
# Nothing to return?
if len(fields_to_return) == 0:
Loading