From 1fb6aea53226c3c73db5564f069590eabf922b4e Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Fri, 10 Jan 2020 10:40:04 -0500 Subject: [PATCH 1/5] Ensure collaborative_annotation is shown in admin --- app/api/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/admin.py b/app/api/admin.py index 64023af1..5a3cf4ce 100644 --- a/app/api/admin.py +++ b/app/api/admin.py @@ -19,7 +19,7 @@ class DocumentAdmin(admin.ModelAdmin): class ProjectAdmin(admin.ModelAdmin): - list_display = ('name', 'description', 'project_type', 'randomize_document_order') + list_display = ('name', 'description', 'project_type', 'randomize_document_order', 'collaborative_annotation') ordering = ('project_type',) search_fields = ('name',) From 73ea4f191284c22f00c8b71fcc387fe5d061dc70 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Fri, 10 Jan 2020 10:41:02 -0500 Subject: [PATCH 2/5] Fix spacing --- app/api/serializers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/serializers.py b/app/api/serializers.py index eaa2af2c..cf3856f2 100644 --- a/app/api/serializers.py +++ b/app/api/serializers.py @@ -120,7 +120,6 @@ class TextClassificationProjectSerializer(ProjectSerializer): class SequenceLabelingProjectSerializer(ProjectSerializer): - class Meta: model = SequenceLabelingProject fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', From af8ca8de19145c1021c052bf3430722fd9cab3c9 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Fri, 10 Jan 2020 10:41:28 -0500 Subject: [PATCH 3/5] Ensure read_only_fields are consistent --- app/api/serializers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/api/serializers.py b/app/api/serializers.py index cf3856f2..e95cae33 100644 --- a/app/api/serializers.py +++ b/app/api/serializers.py @@ -106,7 +106,7 @@ class ProjectSerializer(serializers.ModelSerializer): model = Project fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', 'updated_at', 'randomize_document_order', 'collaborative_annotation') - read_only_fields = ('image', 'updated_at', 'current_users_role') + read_only_fields = ('image', 'updated_at', 'users', 'current_users_role') class TextClassificationProjectSerializer(ProjectSerializer): @@ -115,7 +115,7 @@ class TextClassificationProjectSerializer(ProjectSerializer): model = TextClassificationProject fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', 'updated_at', 'randomize_document_order') - read_only_fields = ('image', 'updated_at', 'users', 'current_users_role') + read_only_fields = ProjectSerializer.Meta.read_only_fields class SequenceLabelingProjectSerializer(ProjectSerializer): @@ -124,7 +124,7 @@ class SequenceLabelingProjectSerializer(ProjectSerializer): model = SequenceLabelingProject fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', 'updated_at', 'randomize_document_order') - read_only_fields = ('image', 'updated_at', 'users', 'current_users_role') + read_only_fields = ProjectSerializer.Meta.read_only_fields class Seq2seqProjectSerializer(ProjectSerializer): @@ -133,7 +133,7 @@ class Seq2seqProjectSerializer(ProjectSerializer): model = Seq2seqProject fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', 'updated_at', 'randomize_document_order') - read_only_fields = ('image', 'updated_at', 'users', 'current_users_role') + read_only_fields = ProjectSerializer.Meta.read_only_fields class ProjectPolymorphicSerializer(PolymorphicSerializer): From b0f6308d97860cd0e558240d8dc1ebb87a56aea5 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Fri, 10 Jan 2020 10:42:01 -0500 Subject: [PATCH 4/5] Ensure fields are consistent --- app/api/serializers.py | 9 +++------ app/api/tests/test_api.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/api/serializers.py b/app/api/serializers.py index e95cae33..fa2e0d26 100644 --- a/app/api/serializers.py +++ b/app/api/serializers.py @@ -113,8 +113,7 @@ class TextClassificationProjectSerializer(ProjectSerializer): class Meta: model = TextClassificationProject - fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', - 'updated_at', 'randomize_document_order') + fields = ProjectSerializer.Meta.fields read_only_fields = ProjectSerializer.Meta.read_only_fields @@ -122,8 +121,7 @@ class SequenceLabelingProjectSerializer(ProjectSerializer): class Meta: model = SequenceLabelingProject - fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', - 'updated_at', 'randomize_document_order') + fields = ProjectSerializer.Meta.fields read_only_fields = ProjectSerializer.Meta.read_only_fields @@ -131,8 +129,7 @@ class Seq2seqProjectSerializer(ProjectSerializer): class Meta: model = Seq2seqProject - fields = ('id', 'name', 'description', 'guideline', 'users', 'current_users_role', 'project_type', 'image', - 'updated_at', 'randomize_document_order') + fields = ProjectSerializer.Meta.fields read_only_fields = ProjectSerializer.Meta.read_only_fields diff --git a/app/api/tests/test_api.py b/app/api/tests/test_api.py index 0a77bb7c..5369fa1e 100644 --- a/app/api/tests/test_api.py +++ b/app/api/tests/test_api.py @@ -111,6 +111,20 @@ class TestProjectListAPI(APITestCase): password=self.super_user_pass) response = self.client.post(self.url, format='json', data=self.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertFalse(response.json().get('collaborative_annotation')) + self.assertFalse(response.json().get('randomize_document_order')) + + def test_allows_superuser_to_create_project_with_flags(self): + self.client.login(username=self.super_user_name, + password=self.super_user_pass) + response = self.client.post(self.url, format='json', data=dict( + collaborative_annotation=True, + randomize_document_order=True, + **self.data, + )) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertTrue(response.json().get('collaborative_annotation')) + self.assertTrue(response.json().get('randomize_document_order')) def test_disallows_project_member_to_create_project(self): self.client.login(username=self.main_project_member_name, From 5c1a5e0a84126f3ec5f89b563b78125a02205f74 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Mon, 13 Jan 2020 09:19:01 -0500 Subject: [PATCH 5/5] Fix codacy --- app/api/tests/test_api.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/api/tests/test_api.py b/app/api/tests/test_api.py index 5369fa1e..46c95466 100644 --- a/app/api/tests/test_api.py +++ b/app/api/tests/test_api.py @@ -117,11 +117,10 @@ class TestProjectListAPI(APITestCase): def test_allows_superuser_to_create_project_with_flags(self): self.client.login(username=self.super_user_name, password=self.super_user_pass) - response = self.client.post(self.url, format='json', data=dict( - collaborative_annotation=True, - randomize_document_order=True, - **self.data, - )) + data = dict(self.data) + data['collaborative_annotation'] = True + data['randomize_document_order'] = True + response = self.client.post(self.url, format='json', data=data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue(response.json().get('collaborative_annotation')) self.assertTrue(response.json().get('randomize_document_order'))