From 06be25d336454b0b3ccb3e4ec9e83eac1fd89273 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 14 Jan 2022 10:11:18 +0900 Subject: [PATCH] Add is_text_project field to ProjectSerializer --- backend/api/models.py | 2 +- backend/api/serializers.py | 2 ++ frontend/domain/models/project/project.ts | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/api/models.py b/backend/api/models.py index 61c12cd6..fd268e94 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -43,7 +43,7 @@ class Project(PolymorphicModel): @property @abc.abstractmethod def is_text_project(self) -> bool: - raise NotImplementedError() + return False def __str__(self): return self.name diff --git a/backend/api/serializers.py b/backend/api/serializers.py index 8fa2bac6..c873b136 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -173,11 +173,13 @@ class ProjectSerializer(serializers.ModelSerializer): 'random_order', 'collaborative_annotation', 'single_class_classification', + 'is_text_project', 'tags' ) read_only_fields = ( 'updated_at', 'users', + 'is_text_project', 'tags' ) diff --git a/frontend/domain/models/project/project.ts b/frontend/domain/models/project/project.ts index e0bb3ca0..2c3c1e1a 100644 --- a/frontend/domain/models/project/project.ts +++ b/frontend/domain/models/project/project.ts @@ -17,6 +17,7 @@ export class ProjectReadItem { public allow_overlapping: boolean, public grapheme_mode: boolean, public tags: Object[], + public is_text_project: boolean, ) {} static valueOf( @@ -34,7 +35,8 @@ export class ProjectReadItem { resourcetype, allow_overlapping, grapheme_mode, - tags + tags, + is_text_project }: { id: number, @@ -50,7 +52,8 @@ export class ProjectReadItem { resourcetype: string, allow_overlapping: boolean, grapheme_mode: boolean, - tags: Object[] + tags: Object[], + is_text_project: boolean } ): ProjectReadItem { return new ProjectReadItem( @@ -67,7 +70,8 @@ export class ProjectReadItem { resourcetype, allow_overlapping, grapheme_mode, - tags + tags, + is_text_project ) } @@ -102,13 +106,7 @@ export class ProjectReadItem { } get isTextProject() { - const allowedProjectTypes = [ - 'DocumentClassification', - 'SequenceLabeling', - 'Seq2seq', - 'IntentDetectionAndSlotFilling' - ] - return allowedProjectTypes.includes(this.project_type) + return this.is_text_project } get hasCategory(): boolean { @@ -143,7 +141,8 @@ export class ProjectReadItem { resourcetype: this.resourcetype, allow_overlapping: this.allow_overlapping, grapheme_mode: this.grapheme_mode, - tags: this.tags + tags: this.tags, + is_text_project: this.is_text_project } } }