CollectionItemView: disallow normal item creation

People should only use transaction/batch
master
Tom Hacohen 5 years ago
parent f6960bb8cb
commit 6c31b8fb30

@ -222,22 +222,8 @@ class CollectionItemViewSet(BaseViewSet):
return context return context
def create(self, request, collection_uid=None): def create(self, request, collection_uid=None):
collection_object = get_object_or_404(self.get_collection_queryset(Collection.objects), uid=collection_uid) # We create using batch and transaction
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
# FIXME: change this to also support bulk update, or have another endpoint for that.
# See https://www.django-rest-framework.org/api-guide/serializers/#customizing-multiple-update
many = isinstance(request.data, list)
serializer = self.serializer_class(data=request.data, many=many)
if serializer.is_valid():
try:
serializer.save(collection=collection_object)
except IntegrityError:
content = {'code': 'integrity_error'}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
return Response({}, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def destroy(self, request, collection_uid=None, uid=None): def destroy(self, request, collection_uid=None, uid=None):
# We can't have destroy because we need to get data from the user (in the body) such as hmac. # We can't have destroy because we need to get data from the user (in the body) such as hmac.

Loading…
Cancel
Save