Skip to content
Snippets Groups Projects
Commit 2eaef534 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

CreateElementTranscriptions

parent 58a96b39
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,7 @@ class ElementTranscriptionsBulk(CreateAPIView):
'value': {
'element_type': 'string',
'transcription_type': 'string',
'source': 'string',
'worker_version': 'string',
'transcriptions': {
'polygon': [[]],
'text': 'string',
......@@ -194,7 +194,6 @@ class ElementTranscriptionsBulk(CreateAPIView):
def perform_create(self, serializer):
elt_type = serializer.validated_data['element_type']
tr_type = serializer.validated_data['transcription_type']
source = serializer.validated_data['source']
worker_version = serializer.validated_data['worker_version']
annotations = serializer.validated_data['transcriptions']
......@@ -280,7 +279,6 @@ class ElementTranscriptionsBulk(CreateAPIView):
element=annotation['element'],
type=tr_type,
zone=None,
source=source,
worker_version=worker_version,
text=annotation['text'],
score=annotation['score']
......
......@@ -353,16 +353,8 @@ class ElementTranscriptionsBulkSerializer(serializers.Serializer):
TranscriptionType,
help_text='A TranscriptionType for created transcriptions'
)
source = DataSourceSlugField(
tool_type=MLToolType.Recognizer,
required=False,
default=None,
help_text='A recognizer DataSource slug, unique per request too. It cannot be set to manual'
)
worker_version = serializers.PrimaryKeyRelatedField(
queryset=WorkerVersion.objects.all(),
required=False,
default=None,
help_text='A WorkerVersion ID that transcriptions will refer to'
)
transcriptions = SimpleTranscriptionSerializer(
......@@ -386,24 +378,6 @@ class ElementTranscriptionsBulkSerializer(serializers.Serializer):
# Use the parent types for validation as elements are in the same corpus
self.fields['element_type'].queryset = ElementType.objects.filter(corpus=self.context['element'].corpus)
def validate(self, data):
data = super().validate(data)
source = data.get('source')
worker_version = data.get('worker_version')
if not source and not worker_version:
raise ValidationError({
'source': ['This field XOR worker_version field must be set to create transcriptions'],
'worker_version': ['This field XOR source field must be set to create transcriptions']
})
elif source and worker_version:
raise ValidationError({
'source': ['You can only refer to a DataSource XOR a WorkerVersion on transcriptions'],
'worker_version': ['You can only refer to a DataSource XOR a WorkerVersion on transcriptions']
})
elif source and source.slug == 'manual':
raise ValidationError({'source': ["Transcriptions source slug cannot be set to manual."]})
return data
class AnnotatedElementSerializer(serializers.Serializer):
"""
......
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