From df75f6bcef66df4961f83080fdcd2ad7a2dce71e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 18 Oct 2021 15:23:10 +0900 Subject: [PATCH] Add fields to SequenceLabelingProject --- .../api/migrations/0016_auto_20211018_0556.py | 65 +++++++++++++++++++ backend/api/models.py | 2 + backend/api/serializers.py | 1 + backend/api/tests/api/test_project.py | 25 +++++++ 4 files changed, 93 insertions(+) create mode 100644 backend/api/migrations/0016_auto_20211018_0556.py diff --git a/backend/api/migrations/0016_auto_20211018_0556.py b/backend/api/migrations/0016_auto_20211018_0556.py new file mode 100644 index 00000000..13724c29 --- /dev/null +++ b/backend/api/migrations/0016_auto_20211018_0556.py @@ -0,0 +1,65 @@ +# Generated by Django 3.2.4 on 2021-10-18 05:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0015_examplestate'), + ] + + operations = [ + migrations.AlterModelOptions( + name='comment', + options={'ordering': ['created_at']}, + ), + migrations.AlterModelOptions( + name='example', + options={'ordering': ['created_at']}, + ), + migrations.AlterModelOptions( + name='label', + options={'ordering': ['created_at']}, + ), + migrations.AddField( + model_name='sequencelabelingproject', + name='allow_overlapping', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='sequencelabelingproject', + name='grapheme_mode', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='autolabelingconfig', + name='label_mapping', + field=models.JSONField(blank=True, default=dict), + ), + migrations.AlterField( + model_name='comment', + name='created_at', + field=models.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name='example', + name='created_at', + field=models.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name='example', + name='filename', + field=models.FileField(default='.', max_length=1024, upload_to=''), + ), + migrations.AlterField( + model_name='label', + name='created_at', + field=models.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name='label', + name='text', + field=models.CharField(db_index=True, max_length=100), + ), + ] diff --git a/backend/api/models.py b/backend/api/models.py index 824d2953..96287d2d 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -56,6 +56,8 @@ class TextClassificationProject(Project): class SequenceLabelingProject(Project): + allow_overlapping = models.BooleanField(default=False) + grapheme_mode = models.BooleanField(default=False) def get_annotation_class(self): return Span diff --git a/backend/api/serializers.py b/backend/api/serializers.py index ca188199..aa3be273 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -193,6 +193,7 @@ class SequenceLabelingProjectSerializer(ProjectSerializer): class Meta(ProjectSerializer.Meta): model = SequenceLabelingProject + fields = ProjectSerializer.Meta.fields + ('allow_overlapping', 'grapheme_mode') class Seq2seqProjectSerializer(ProjectSerializer): diff --git a/backend/api/tests/api/test_project.py b/backend/api/tests/api/test_project.py index c3ea022c..f200db8c 100644 --- a/backend/api/tests/api/test_project.py +++ b/backend/api/tests/api/test_project.py @@ -52,6 +52,31 @@ class TestProjectCreate(CRUDMixin): self.assert_create(expected=status.HTTP_403_FORBIDDEN) +class TestSequenceLabelingProjectCreation(CRUDMixin): + + @classmethod + def setUpTestData(cls): + create_default_roles() + cls.user = make_user() + cls.url = reverse(viewname='project_list') + cls.data = { + 'name': 'example', + 'project_type': 'SequenceLabeling', + 'description': 'example', + 'guideline': 'example', + 'allow_overlapping': True, + 'grapheme_mode': True, + 'resourcetype': 'SequenceLabelingProject' + } + + def test_allows_staff_user_to_create_project(self): + self.user.is_staff = True + self.user.save() + response = self.assert_create(self.user, status.HTTP_201_CREATED) + self.assertEqual(response.data['allow_overlapping'], self.data['allow_overlapping']) + self.assertEqual(response.data['grapheme_mode'], self.data['grapheme_mode']) + + class TestProjectDetailAPI(CRUDMixin): @classmethod