API: Upload new version of an extension #138
@ -7,6 +7,7 @@ from rest_framework.views import APIView
|
|||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
from common.compare import is_in_version_range, version
|
from common.compare import is_in_version_range, version
|
||||||
from extensions.models import Extension, Platform, Version
|
from extensions.models import Extension, Platform, Version
|
||||||
@ -207,18 +208,19 @@ class UploadExtensionVersionView(APIView):
|
|||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return Response({'message': form.errors}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({'message': form.errors}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# Create the file instance
|
with transaction.atomic():
|
||||||
file_instance = form.save(commit=False)
|
# Create the file instance
|
||||||
file_instance.user = user
|
file_instance = form.save(commit=False)
|
||||||
file_instance.save()
|
file_instance.user = user
|
||||||
|
file_instance.save()
|
||||||
|
|||||||
|
|
||||||
# Create the version from the file
|
# Create the version from the file
|
||||||
version = Version.objects.update_or_create(
|
version = Version.objects.update_or_create(
|
||||||
extension=extension,
|
extension=extension,
|
||||||
file=file_instance,
|
file=file_instance,
|
||||||
release_notes=release_notes,
|
release_notes=release_notes,
|
||||||
**file_instance.parsed_version_fields,
|
**file_instance.parsed_version_fields,
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user
btw, what's the use case for update here? why we are not just creating the object?
I guess I was just copying the same code we used on UploadFileView.form_valid. Which probably should be changed as well.
Anyways, changing the PR to use create(), and will merge after testing.