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
8b01b3dc
Commit
8b01b3dc
authored
5 years ago
by
Valentin Rigal
Committed by
Erwan Rouchet
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix transcriptionentity create validation
parent
44468856
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/api/entities.py
+21
-7
21 additions, 7 deletions
arkindex/documents/api/entities.py
arkindex/documents/serializers/entities.py
+4
-6
4 additions, 6 deletions
arkindex/documents/serializers/entities.py
with
25 additions
and
13 deletions
arkindex/documents/api/entities.py
+
21
−
7
View file @
8b01b3dc
...
...
@@ -8,7 +8,8 @@ from arkindex.documents.serializers.entities import (
TranscriptionEntitySerializer
,
TranscriptionEntityDetailsSerializer
)
from
arkindex.documents.serializers.elements
import
ElementSerializer
from
rest_framework.exceptions
import
ValidationError
from
rest_framework
import
serializers
from
django.core.exceptions
import
ValidationError
from
arkindex.project.permissions
import
IsVerified
...
...
@@ -32,7 +33,7 @@ class CorpusRoles(CorpusACLMixin, ListCreateAPIView):
child_type
=
data
[
'
child_type
'
],
corpus_id
=
self
.
request
.
parser_context
[
'
kwargs
'
][
'
pk
'
]
).
exists
():
raise
ValidationError
({
raise
serializers
.
ValidationError
({
'
corpus
'
:
[
'
Role already exists in this corpus
'
],
'
id
'
:
self
.
request
.
parser_context
[
'
kwargs
'
][
'
pk
'
]
})
...
...
@@ -101,14 +102,27 @@ class TranscriptionEntityCreate(CreateAPIView):
def
get_serializer_context
(
self
):
context
=
super
().
get_serializer_context
()
if
not
self
.
kwargs
.
get
(
'
pk
'
)
:
#
Do not raise in order to build openapi doc
if
not
self
.
request
:
#
OpenAPI cannot pass request context
return
context
tr
=
Transcription
.
objects
.
filter
(
id
=
self
.
kwargs
[
'
pk
'
]).
first
()
if
not
tr
or
tr
.
element
.
corpus
not
in
Corpus
.
objects
.
readable
(
self
.
request
.
user
):
raise
ValidationError
({
'
transcription
'
:
[
'
invalid UUID or Corpus write-access is forbidden
'
]})
tr
=
Transcription
.
objects
.
filter
(
id
=
self
.
kwargs
.
get
(
'
pk
'
),
element__corpus__in
=
Corpus
.
objects
.
writable
(
self
.
request
.
user
)
).
first
()
return
{
**
context
,
'
transcription
'
:
tr
}
def
perform_create
(
self
,
serializer
):
data
=
serializer
.
validated_data
if
TranscriptionEntity
.
objects
.
filter
(
**
data
).
exists
():
raise
serializers
.
ValidationError
({
'
__all__
'
:
[
'
Entity is already linked to this transcription at this position
'
]
})
try
:
TranscriptionEntity
(
**
data
).
full_clean
()
except
ValidationError
as
e
:
raise
serializers
.
ValidationError
(
serializers
.
as_serializer_error
(
e
))
super
().
perform_create
(
serializer
)
class
TranscriptionEntities
(
ListAPIView
):
"""
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/serializers/entities.py
+
4
−
6
View file @
8b01b3dc
from
rest_framework
import
serializers
from
django.core.exceptions
import
ValidationError
as
DjangoValidationError
from
arkindex.documents.models
import
\
Corpus
,
Entity
,
EntityLink
,
EntityRole
,
TranscriptionEntity
from
arkindex_common.enums
import
EntityType
...
...
@@ -143,11 +142,10 @@ class TranscriptionEntitySerializer(serializers.ModelSerializer):
def
validate
(
self
,
data
):
data
=
super
().
validate
(
data
)
data
[
'
transcription
'
]
=
self
.
context
[
'
transcription
'
]
try
:
# Assert link is not already present in database and check clean constraints
TranscriptionEntity
(
**
data
).
full_clean
()
except
DjangoValidationError
as
e
:
raise
serializers
.
ValidationError
(
serializers
.
as_serializer_error
(
e
))
if
not
data
[
'
transcription
'
]:
raise
serializers
.
ValidationError
({
'
transcription
'
:
[
'
invalid UUID or Corpus write-access is forbidden
'
]
})
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