Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
7dc58d90
Commit
7dc58d90
authored
4 years ago
by
Valentin Rigal
Browse files
Options
Downloads
Patches
Plain Diff
CreateTranscription
parent
e5a43a34
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/api/ml.py
+1
-1
1 addition, 1 deletion
arkindex/documents/api/ml.py
arkindex/documents/serializers/ml.py
+15
-35
15 additions, 35 deletions
arkindex/documents/serializers/ml.py
with
16 additions
and
36 deletions
arkindex/documents/api/ml.py
+
1
−
1
View file @
7dc58d90
...
...
@@ -111,7 +111,7 @@ class TranscriptionEdit(RetrieveUpdateDestroyAPIView):
errors
=
defaultdict
(
list
)
if
Right
.
Write
not
in
rights
:
errors
[
'
__all__
'
].
append
(
'
A write access to transcription element corpus is required.
'
)
if
transcription
.
source
.
slug
!=
'
manual
'
:
if
transcription
.
worker_version
or
transcription
.
source
and
transcription
.
source
.
slug
!=
'
manual
'
:
errors
[
'
__all__
'
].
append
(
'
Only manual transcriptions can be edited.
'
)
if
(
errors
):
raise
PermissionDenied
(
errors
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/serializers/ml.py
+
15
−
35
View file @
7dc58d90
...
...
@@ -289,13 +289,12 @@ class TranscriptionCreateSerializer(serializers.ModelSerializer):
Allows the insertion of a manual transcription attached to an element
"""
type
=
EnumField
(
TranscriptionType
)
source
=
DataSourceSlugField
(
tool_type
=
MLToolType
.
Recognizer
,
required
=
False
)
worker_version
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
WorkerVersion
.
objects
.
all
(),
required
=
False
,
allow_null
=
True
)
score
=
serializers
.
FloatField
(
min_value
=
0
,
max_value
=
1
,
required
=
False
)
class
Meta
:
model
=
Transcription
fields
=
(
'
text
'
,
'
type
'
,
'
source
'
,
'
worker_version
'
,
'
score
'
)
fields
=
(
'
text
'
,
'
type
'
,
'
worker_version
'
,
'
score
'
)
def
validate
(
self
,
data
):
data
=
super
().
validate
(
data
)
...
...
@@ -305,46 +304,27 @@ class TranscriptionCreateSerializer(serializers.ModelSerializer):
if
not
element
.
zone_id
:
raise
ValidationError
({
'
element
'
:
[
'
The element has no zone
'
]})
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 a transcription
'
],
'
worker_version
'
:
[
'
This field XOR source field must be set to create a transcription
'
]
})
elif
source
and
worker_version
:
raise
ValidationError
({
'
source
'
:
[
'
You can only refer to a DataSource XOR a WorkerVersion on a transcription
'
],
'
worker_version
'
:
[
'
You can only refer to a DataSource XOR a WorkerVersion on a transcription
'
]
})
elif
source
:
slug
=
source
.
slug
if
slug
==
'
manual
'
:
# Assert the type is allowed for manual transcription
allowed_transcription
=
element
.
type
.
allowed_transcription
if
not
allowed_transcription
:
raise
ValidationError
({
'
element
'
:
[
'
The element type does not allow creating a manual transcription
'
]})
if
data
[
'
type
'
]
is
not
allowed_transcription
:
raise
ValidationError
({
'
type
'
:
[
f
"
Only transcriptions of type
'
{
allowed_transcription
.
value
}
'
are allowed for this element
"
]})
return
data
if
worker_version
is
None
:
# Assert the type is allowed for manual transcription
allowed_transcription
=
element
.
type
.
allowed_transcription
if
not
allowed_transcription
:
raise
ValidationError
({
'
element
'
:
[
'
The element type does not allow creating a manual transcription
'
]})
if
data
[
'
type
'
]
is
not
allowed_transcription
:
raise
ValidationError
({
'
type
'
:
[
f
"
Only transcriptions of type
'
{
allowed_transcription
.
value
}
'
are allowed for this element
"
]})
return
data
# Additional validation for transcriptions with a
n internal source
# Additional validation for transcriptions with a
worker version
if
not
data
.
get
(
'
score
'
):
raise
ValidationError
({
'
score
'
:
[
'
This field is required for
non manual sources
.
'
]})
raise
ValidationError
({
'
score
'
:
[
'
This field is required for
transcription with a worker version
.
'
]})
user
=
self
.
context
[
'
request
'
].
user
if
(
not
user
or
not
user
.
is_internal
):
if
source
:
raise
ValidationError
({
'
source
'
:
[
'
An internal user is required to create a transcription with
'
f
'
the internal source
"
{
slug
}
"'
]})
raise
ValidationError
({
'
worker_version
'
:
[
'
An internal user is required to create a transcription with
'
f
'
the worker_version
"
{
worker_version
.
id
}
"'
'
An internal user is required to create a transcription refering to a worker_version
'
]})
return
data
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment