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.

39 lines
1.4 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. use_relation = getattr(project, "use_relation", False)
  16. options = Options.filter_by_task(project.project_type, use_relation)
  17. return Response(data=options, status=status.HTTP_200_OK)
  18. class DatasetImportAPI(APIView):
  19. permission_classes = [IsAuthenticated & IsProjectAdmin]
  20. def post(self, request, *args, **kwargs):
  21. upload_ids = request.data.pop("uploadIds")
  22. file_format = request.data.pop("format")
  23. task = request.data.pop("task")
  24. celery_task = import_dataset.delay(
  25. user_id=request.user.id,
  26. project_id=self.kwargs["project_id"],
  27. file_format=file_format,
  28. upload_ids=upload_ids,
  29. task=task,
  30. **request.data,
  31. )
  32. return Response({"task_id": celery_task.task_id})