From 9a69140be18b27aa0b9127bde9d10906f6106402 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 24 Mar 2022 15:47:19 +0900 Subject: [PATCH] Update DatasetImportAPI to upload a file --- backend/data_import/views.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/data_import/views.py b/backend/data_import/views.py index d3652b50..8ba650d9 100644 --- a/backend/data_import/views.py +++ b/backend/data_import/views.py @@ -1,14 +1,13 @@ import os from django.shortcuts import get_object_or_404 -from django_drf_filepond.api import store_upload from django_drf_filepond.models import TemporaryUpload from rest_framework import status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from .celery_tasks import import_dataset +from .celery_tasks import import_dataset, upload_to_store from .pipeline.catalog import Options from projects.models import Project from projects.permissions import IsProjectAdmin @@ -32,12 +31,16 @@ class DatasetImportAPI(APIView): upload_ids = request.data.pop("uploadIds") file_format = request.data.pop("format") - tus = [TemporaryUpload.objects.get(upload_id=upload_id) for upload_id in upload_ids] - sus = [ - store_upload(tu.upload_id, destination_file_path=os.path.join(tu.file.name, tu.upload_name)) for tu in tus - ] - filenames = [su.file.path for su in sus] + temporary_uploads = TemporaryUpload.objects.filter(upload_id__in=upload_ids) + file_paths = [tu.get_file_path() for tu in temporary_uploads] + save_names = {tu.get_file_path(): os.path.join(tu.file.name, tu.upload_name) for tu in temporary_uploads} task = import_dataset.delay( - user_id=request.user.id, project_id=project_id, filenames=filenames, file_format=file_format, **request.data + user_id=request.user.id, + project_id=project_id, + filenames=file_paths, + file_format=file_format, + save_names=save_names, + **request.data, ) - return Response({"task_id": task.task_id}) + upload_task = upload_to_store.delay(upload_ids) + return Response({"task_id": task.task_id, "uploadTaskId": upload_task.task_id})