|
|
@ -0,0 +1,42 @@ |
|
|
|
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 .catalog import Options |
|
|
|
from ...models import Project |
|
|
|
from ...permissions import IsProjectAdmin |
|
|
|
from ...tasks import injest_data |
|
|
|
|
|
|
|
|
|
|
|
class DatasetCatalog(APIView): |
|
|
|
permission_classes = [IsAuthenticated & IsProjectAdmin] |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
project_id = request.query_params['project_id'] |
|
|
|
project = get_object_or_404(Project, pk=project_id) |
|
|
|
options = Options.filter_by_task(project.project_type) |
|
|
|
return Response(data=options, status=status.HTTP_200_OK) |
|
|
|
|
|
|
|
|
|
|
|
class UploadAPI(APIView): |
|
|
|
permission_classes = [IsAuthenticated & IsProjectAdmin] |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
project_id = self.kwargs['project_id'] |
|
|
|
upload_ids = request.data('upload_ids') |
|
|
|
format = request.data('format') |
|
|
|
|
|
|
|
tus = [TemporaryUpload.objects.get(upload_id=upload_id) for upload_id in upload_ids] |
|
|
|
sus = [store_upload(tu.upload_id, destination_file_path=tu.upload_name) for tu in tus] |
|
|
|
filenames = [su.file.path for su in sus] |
|
|
|
task = injest_data.delay( |
|
|
|
user_id=request.user.id, |
|
|
|
project_id=project_id, |
|
|
|
filenames=filenames, |
|
|
|
format=format |
|
|
|
) |
|
|
|
return Response({'task_id': task.task_id}) |