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
39a4527f
Verified
Commit
39a4527f
authored
2 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Allow a manual TranscriptionEntity that is the same as a WorkerRun's
parent
0893cf01
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1911
Allow a manual TranscriptionEntity that is the same as a WorkerRun's
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/entities.py
+11
-5
11 additions, 5 deletions
arkindex/documents/serializers/entities.py
arkindex/documents/tests/test_entities_api.py
+36
-0
36 additions, 0 deletions
arkindex/documents/tests/test_entities_api.py
with
47 additions
and
5 deletions
arkindex/documents/serializers/entities.py
+
11
−
5
View file @
39a4527f
...
...
@@ -426,12 +426,18 @@ class TranscriptionEntityCreateSerializer(serializers.ModelSerializer):
if
worker_run
is
not
None
:
data
[
'
worker_version_id
'
]
=
worker_run
.
version_id
existing_transcription_entities
=
TranscriptionEntity
.
objects
.
filter
(
transcription
=
data
[
'
transcription
'
],
entity
=
data
[
'
entity
'
],
offset
=
data
[
'
offset
'
],
length
=
data
[
'
length
'
])
if
worker_run
:
if
existing_transcription_entities
.
filter
(
worker_run
=
worker_run
).
exists
():
existing_transcription_entities
=
TranscriptionEntity
.
objects
.
filter
(
transcription
=
data
[
'
transcription
'
],
entity
=
data
[
'
entity
'
],
offset
=
data
[
'
offset
'
],
length
=
data
[
'
length
'
],
worker_run
=
worker_run
,
)
if
existing_transcription_entities
.
exists
():
if
worker_run
:
errors
[
'
__all__
'
]
=
[
'
This entity is already linked to this transcription by this worker run at this position.
'
]
elif
existing_transcription_entities
.
exists
()
:
errors
[
'
__all__
'
]
=
[
'
This entity is already linked to this transcription at this position.
'
]
else
:
errors
[
'
__all__
'
]
=
[
'
This entity is already linked to this transcription at this position.
'
]
if
errors
:
raise
serializers
.
ValidationError
(
errors
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_entities_api.py
+
36
−
0
View file @
39a4527f
...
...
@@ -975,6 +975,42 @@ class TestEntitiesAPI(FixtureAPITestCase):
'
__all__
'
:
[
'
This entity is already linked to this transcription by this worker run at this position.
'
]
})
def
test_create_transcription_entity_manual_existing_worker_run
(
self
):
"""
A manual TranscriptionEntity can be created even when one exists with the same attributes from a WorkerRun
"""
self
.
client
.
force_login
(
self
.
internal_user
)
TranscriptionEntity
.
objects
.
create
(
transcription
=
self
.
transcription
,
entity
=
self
.
entity
,
offset
=
4
,
length
=
8
,
worker_run
=
self
.
worker_run
,
worker_version
=
self
.
worker_version_1
)
with
self
.
assertNumQueries
(
6
):
response
=
self
.
client
.
post
(
reverse
(
'
api:transcription-entity-create
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
transcription
.
id
)}),
data
=
{
'
entity
'
:
str
(
self
.
entity
.
id
),
'
offset
'
:
4
,
'
length
'
:
8
,
},
format
=
'
json
'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
transcription_entity
=
self
.
transcription
.
transcription_entities
.
filter
(
worker_run
=
None
,
entity
=
self
.
entity
).
get
()
self
.
assertDictEqual
(
response
.
json
(),
{
'
entity
'
:
str
(
transcription_entity
.
entity
.
id
),
'
offset
'
:
transcription_entity
.
offset
,
'
length
'
:
transcription_entity
.
length
,
'
worker_run
'
:
None
,
'
confidence
'
:
None
}
)
def
test_create_transcription_entity_key_missing
(
self
):
self
.
client
.
force_login
(
self
.
user
)
data
=
self
.
tr_entities_sample
...
...
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