From af2f408991d6683fd2315b6167ae8ebc53fa9e4e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 8 Apr 2021 21:17:07 +0900 Subject: [PATCH] Update catalog --- app/api/views/__init__.py | 2 +- app/api/views/upload/catalog.py | 6 ++++-- app/api/views/upload/dataset.py | 2 +- app/api/views/upload/factory.py | 4 ++-- app/api/views/upload/view.py | 9 +++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/api/views/__init__.py b/app/api/views/__init__.py index c851c30c..1210f02f 100644 --- a/app/api/views/__init__.py +++ b/app/api/views/__init__.py @@ -9,5 +9,5 @@ from .project import * from .role import * from .statistics import * from .task import * -from .user import * from .upload import * +from .user import * diff --git a/app/api/views/upload/catalog.py b/app/api/views/upload/catalog.py index 56a4e8c2..795bebf6 100644 --- a/app/api/views/upload/catalog.py +++ b/app/api/views/upload/catalog.py @@ -2,8 +2,10 @@ from collections import defaultdict from typing import Dict, List, Type from pydantic import BaseModel +from typing_extensions import Literal + +from ...models import DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING -from ...models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ CSV = 'CSV' FastText = 'fastText' JSON = 'JSON' @@ -18,7 +20,7 @@ class OptionColumn(BaseModel): class OptionDelimiter(OptionColumn): - delimiter: str = ',' + delimiter: Literal[',', '\t', ';', '|', ' '] = ',' class OptionNone(BaseModel): diff --git a/app/api/views/upload/dataset.py b/app/api/views/upload/dataset.py index 24f930bf..8a813094 100644 --- a/app/api/views/upload/dataset.py +++ b/app/api/views/upload/dataset.py @@ -118,7 +118,7 @@ class CsvDataset(Dataset): column_data = self.kwargs.get('column_data', 'text') if column_data not in header: - message = f'{column_data} does not exist in the header: {header}' + message = f'Column `{column_data}` does not exist in the header: {header}' raise FileParseException(filename, 1, message) for line_num, row in enumerate(reader, start=2): diff --git a/app/api/views/upload/factory.py b/app/api/views/upload/factory.py index ca714000..7b5bfd42 100644 --- a/app/api/views/upload/factory.py +++ b/app/api/views/upload/factory.py @@ -1,5 +1,5 @@ -from . import data, dataset, label, catalog -from ...models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ +from ...models import DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING +from . import catalog, data, dataset, label def get_data_class(project_type: str): diff --git a/app/api/views/upload/view.py b/app/api/views/upload/view.py index ca4568e5..5352e4a0 100644 --- a/app/api/views/upload/view.py +++ b/app/api/views/upload/view.py @@ -6,10 +6,10 @@ 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 +from .catalog import Options class DatasetCatalog(APIView): @@ -27,8 +27,8 @@ class UploadAPI(APIView): def post(self, request, *args, **kwargs): project_id = self.kwargs['project_id'] - upload_ids = request.data['uploadIds'] - format = request.data['format'] + upload_ids = request.data.pop('uploadIds') + 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=tu.upload_name) for tu in tus] @@ -37,6 +37,7 @@ class UploadAPI(APIView): user_id=request.user.id, project_id=project_id, filenames=filenames, - format=format + format=format, + **request.data ) return Response({'task_id': task.task_id})