Skip to content
Snippets Groups Projects
Commit eaa30d3a authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Output transcriptions IDs in CreateElementTranscriptions

parent 6213a650
No related branches found
No related tags found
1 merge request!1285Output transcriptions IDs in CreateElementTranscriptions
......@@ -288,12 +288,14 @@ class ElementTranscriptionsBulk(CreateAPIView):
# Create transcriptions for the elements if they does not exist
transcriptions = []
for annotation in annotations:
transcriptions.append(Transcription(
transcription = Transcription(
element=annotation['element'],
worker_version=worker_version,
text=annotation['text'],
confidence=annotation['confidence'],
))
)
annotation['id'] = transcription.id
transcriptions.append(transcription)
# Create missing transcriptions in bulk
Transcription.objects.bulk_create(transcriptions)
......
......@@ -360,7 +360,8 @@ class AnnotatedElementSerializer(serializers.Serializer):
Returns annotated element IDs specifying if they have been created
to hold a transcription.
"""
id = serializers.UUIDField(source='element.id')
id = serializers.UUIDField()
element_id = serializers.UUIDField(source='element.id')
# Specify if the element has been created for the annotation
created = serializers.BooleanField(default=False)
......
......@@ -7,7 +7,7 @@ from django.urls import reverse
from rest_framework import status
from arkindex.dataimport.models import WorkerVersion
from arkindex.documents.models import Corpus, Element
from arkindex.documents.models import Corpus, Element, Transcription
from arkindex.project.tests import FixtureAPITestCase
......@@ -128,7 +128,6 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(created_elts.count(), 101)
self.assertEqual(created_elts.count(), 101)
# Each annotated element has a transcription
self.assertEqual(created_elts.annotate(ts_count=Count('transcriptions')).filter(ts_count=1).count(), 100)
......@@ -310,14 +309,20 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
first_elt = created_elts.get(transcriptions__text='stuck')
second_elt = created_elts.get(transcriptions__text='stock')
first_tr = Transcription.objects.get(text="stuck")
second_tr = Transcription.objects.get(text="stock")
thrid_td = Transcription.objects.get(text="stack")
self.assertListEqual(response.json(), [{
'id': str(first_elt.id),
'id': str(first_tr.id),
'element_id': str(first_elt.id),
'created': True
}, {
'id': str(second_elt.id),
'id': str(second_tr.id),
'element_id': str(second_elt.id),
'created': True
}, {
'id': str(self.line.id),
'id': str(thrid_td.id),
'element_id': str(self.line.id),
'created': False
}])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment