Browse Source

Update DatasetImportAPI to upload a file

pull/1779/head
Hironsan 2 years ago
parent
commit
9a69140be1
1 changed files with 12 additions and 9 deletions
  1. 21
      backend/data_import/views.py

21
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})
Loading…
Cancel
Save