Browse Source

Add uuid field to BaseData

pull/1823/head
Hironsan 3 years ago
parent
commit
9981a37805
1 changed files with 8 additions and 5 deletions
  1. 13
      backend/data_import/pipeline/data.py

13
backend/data_import/pipeline/data.py

@ -2,7 +2,7 @@ import abc
import uuid
from typing import Any, Dict
from pydantic import BaseModel, validator
from pydantic import UUID4, BaseModel, validator
from examples.models import Example
from projects.models import Project
@ -11,6 +11,11 @@ from projects.models import Project
class BaseData(BaseModel, abc.ABC):
filename: str
upload_name: str
uuid: UUID4
def __init__(self, **data):
data["uuid"] = uuid.uuid4()
super().__init__(**data)
@classmethod
def parse(cls, **kwargs):
@ -36,7 +41,7 @@ class TextData(BaseData):
def create(self, project: Project, meta: Dict[Any, Any]) -> Example:
return Example(
uuid=uuid.uuid4(),
uuid=self.uuid,
project=project,
filename=self.filename,
upload_name=self.upload_name,
@ -47,6 +52,4 @@ class TextData(BaseData):
class FileData(BaseData):
def create(self, project: Project, meta: Dict[Any, Any]) -> Example:
return Example(
uuid=uuid.uuid4(), project=project, filename=self.filename, upload_name=self.upload_name, meta=meta
)
return Example(uuid=self.uuid, project=project, filename=self.filename, upload_name=self.upload_name, meta=meta)
Loading…
Cancel
Save