From d1e121390d4000d06416fc3322f2c7e3fc444017 Mon Sep 17 00:00:00 2001 From: Valentin Rigal <rigal@teklia.com> Date: Thu, 3 Sep 2020 12:47:05 +0000 Subject: [PATCH] Serialize worker version ID for an element and its classifications --- arkindex/documents/serializers/elements.py | 16 ++++++++++++++-- arkindex/documents/serializers/ml.py | 3 ++- arkindex/documents/tests/test_create_elements.py | 3 +++ arkindex/documents/tests/test_moderation.py | 12 ++++++++---- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/arkindex/documents/serializers/elements.py b/arkindex/documents/serializers/elements.py index 7d6a9da67b..4c86b979b5 100644 --- a/arkindex/documents/serializers/elements.py +++ b/arkindex/documents/serializers/elements.py @@ -231,8 +231,20 @@ class ElementSerializer(ElementSlimSerializer): class Meta: model = Element - fields = ElementSlimSerializer.Meta.fields + ('metadata', 'classifications', 'image', 'polygon', 'source') - read_only_fields = ElementSlimSerializer.Meta.read_only_fields + ('metadata', 'classifications', 'source') + fields = ElementSlimSerializer.Meta.fields + ( + 'metadata', + 'classifications', + 'image', + 'polygon', + 'source', + 'worker_version' + ) + read_only_fields = ElementSlimSerializer.Meta.read_only_fields + ( + 'metadata', + 'classifications', + 'source', + 'worker_version' + ) def create(self, *args, **kwargs): instance = super().create(*args, **kwargs) diff --git a/arkindex/documents/serializers/ml.py b/arkindex/documents/serializers/ml.py index 8a139a3e79..0aff55e168 100644 --- a/arkindex/documents/serializers/ml.py +++ b/arkindex/documents/serializers/ml.py @@ -90,7 +90,8 @@ class ClassificationSerializer(serializers.ModelSerializer): 'ml_class', 'state', 'confidence', - 'high_confidence' + 'high_confidence', + 'worker_version' ) diff --git a/arkindex/documents/tests/test_create_elements.py b/arkindex/documents/tests/test_create_elements.py index cfda5a232c..a92ae208a9 100644 --- a/arkindex/documents/tests/test_create_elements.py +++ b/arkindex/documents/tests/test_create_elements.py @@ -69,6 +69,7 @@ class TestCreateElements(FixtureAPITestCase): 'thumbnail_put_url': None, 'thumbnail_url': volume.thumbnail.s3_url, 'source': None, + 'worker_version': None, 'classifications': [], 'metadata': [], 'corpus': { @@ -107,6 +108,7 @@ class TestCreateElements(FixtureAPITestCase): 'thumbnail_put_url': None, 'thumbnail_url': None, 'source': None, + 'worker_version': None, 'classifications': [], 'metadata': [], 'corpus': { @@ -246,6 +248,7 @@ class TestCreateElements(FixtureAPITestCase): 'thumbnail_put_url': None, 'thumbnail_url': None, 'source': None, + 'worker_version': None, 'classifications': [], 'metadata': [], 'corpus': { diff --git a/arkindex/documents/tests/test_moderation.py b/arkindex/documents/tests/test_moderation.py index b9f3977843..33c3825bc8 100644 --- a/arkindex/documents/tests/test_moderation.py +++ b/arkindex/documents/tests/test_moderation.py @@ -277,7 +277,8 @@ class TestClasses(FixtureAPITestCase): }, 'state': ClassificationState.Validated.value, 'confidence': classification.confidence, - 'high_confidence': False + 'high_confidence': False, + 'worker_version': None }) # Ensure moderator has been set @@ -310,7 +311,8 @@ class TestClasses(FixtureAPITestCase): }, 'state': ClassificationState.Rejected.value, 'confidence': classification.confidence, - 'high_confidence': False + 'high_confidence': False, + 'worker_version': None }) # Ensure moderator has been set @@ -361,7 +363,8 @@ class TestClasses(FixtureAPITestCase): }, 'state': ClassificationState.Rejected.value, 'confidence': classification.confidence, - 'high_confidence': False + 'high_confidence': False, + 'worker_version': None }) # Then try to validate @@ -383,7 +386,8 @@ class TestClasses(FixtureAPITestCase): }, 'state': ClassificationState.Validated.value, 'confidence': classification.confidence, - 'high_confidence': False + 'high_confidence': False, + 'worker_version': None }) def test_classification_selection_requires_login(self): -- GitLab