You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
  1. from django.shortcuts import get_object_or_404
  2. from rest_framework import status
  3. from rest_framework.permissions import IsAuthenticated
  4. from rest_framework.response import Response
  5. from rest_framework.views import APIView
  6. from .celery_tasks import import_dataset
  7. from .pipeline.catalog import Options
  8. from projects.models import Project
  9. from projects.permissions import IsProjectAdmin
  10. class DatasetCatalog(APIView):
  11. permission_classes = [IsAuthenticated & IsProjectAdmin]
  12. def get(self, request, *args, **kwargs):
  13. project_id = kwargs["project_id"]
  14. project = get_object_or_404(Project, pk=project_id)
  15. options = Options.filter_by_task(project.project_type)
  16. return Response(data=options, status=status.HTTP_200_OK)
  17. class DatasetImportAPI(APIView):
  18. permission_classes = [IsAuthenticated & IsProjectAdmin]
  19. def post(self, request, *args, **kwargs):
  20. upload_ids = request.data.pop("uploadIds")
  21. file_format = request.data.pop("format")
  22. task = import_dataset.delay(
  23. user_id=request.user.id,
  24. project_id=self.kwargs["project_id"],
  25. file_format=file_format,
  26. upload_ids=upload_ids,
  27. **request.data,
  28. )
  29. return Response({"task_id": task.task_id})