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
4ff58dfe
Commit
4ff58dfe
authored
5 years ago
by
Valentin Rigal
Committed by
Erwan Rouchet
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Api transcriptions list
parent
44384873
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex/documents/api/elements.py
+34
-1
34 additions, 1 deletion
arkindex/documents/api/elements.py
arkindex/documents/tests/test_elements_api.py
+19
-1
19 additions, 1 deletion
arkindex/documents/tests/test_elements_api.py
arkindex/project/api_v1.py
+4
-2
4 additions, 2 deletions
arkindex/project/api_v1.py
with
57 additions
and
4 deletions
arkindex/documents/api/elements.py
+
34
−
1
View file @
4ff58dfe
from
rest_framework.generics
import
\
ListAPIView
,
ListCreateAPIView
,
RetrieveAPIView
,
RetrieveUpdateAPIView
,
RetrieveUpdateDestroyAPIView
from
arkindex.project.pagination
import
PageNumberPagination
from
rest_framework.exceptions
import
ValidationError
from
django.db.models
import
prefetch_related_objects
from
arkindex.documents.serializers.light
import
PageLightSerializer
from
arkindex.documents.serializers.elements
import
(
ElementSerializer
,
ElementLightSerializer
,
CorpusSerializer
,
PageSerializer
,
ActSerializer
,
SurfaceSerializer
,
)
from
arkindex.documents.models
import
Element
,
ElementType
,
Page
,
Act
,
Corpus
,
Right
from
arkindex.documents.serializers.ml
import
TranscriptionSerializer
from
arkindex.documents.models
import
(
Element
,
ElementType
,
Page
,
Act
,
TranscriptionType
,
Transcription
,
Corpus
,
Right
,
)
from
arkindex.project.mixins
import
CorpusACLMixin
from
arkindex.project.permissions
import
IsVerifiedOrReadOnly
...
...
@@ -177,3 +183,30 @@ class ActEdit(RetrieveAPIView):
act
.
parent_elements
=
Element
.
objects
.
get_ascending_paths
(
act
.
id
)
act
.
child_elements
=
Element
.
objects
.
get_descending
(
act
.
id
)
return
act
class
TranscriptionsPagination
(
PageNumberPagination
):
page_size
=
100
class
ElementTranscriptions
(
ListAPIView
):
"""
Get transcriptions corresponding to a specific element
Transcriptions can be filtered by type
"""
serializer_class
=
TranscriptionSerializer
pagination_class
=
TranscriptionsPagination
def
get_queryset
(
self
):
queryset
=
Transcription
.
objects
.
filter
(
element_id
=
self
.
kwargs
[
'
pk
'
],
element__corpus__in
=
Corpus
.
objects
.
readable
(
self
.
request
.
user
),
).
prefetch_related
(
'
zone__image__server
'
,
'
source
'
).
order_by
(
'
id
'
)
req_type
=
self
.
request
.
query_params
.
get
(
'
type
'
)
if
req_type
:
try
:
req_type
=
TranscriptionType
(
req_type
)
queryset
=
queryset
.
filter
(
type
=
req_type
)
except
ValueError
:
raise
ValidationError
({
'
type
'
:
'
Not a valid transcription type
'
})
return
queryset
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_elements_api.py
+
19
−
1
View file @
4ff58dfe
from
django.urls
import
reverse
from
rest_framework
import
status
from
arkindex.documents.models
import
Element
,
ElementType
from
arkindex.documents.models
import
Element
,
ElementType
,
DataSource
,
TranscriptionType
from
arkindex.project.tests
import
FixtureAPITestCase
...
...
@@ -10,6 +10,8 @@ class TestElementsAPI(FixtureAPITestCase):
def
setUpTestData
(
cls
):
super
().
setUpTestData
()
cls
.
vol
=
Element
.
objects
.
get
(
name
=
'
Volume 1
'
,
type
=
ElementType
.
Volume
,
corpus
=
cls
.
corpus
)
cls
.
page
=
Element
.
objects
.
filter
(
type
=
ElementType
.
Page
,
corpus
=
cls
.
corpus
).
first
().
page
cls
.
src
=
DataSource
.
objects
.
get
(
slug
=
'
test
'
)
def
test_get_element
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
api:element-retrieve
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
vol
.
id
)}))
...
...
@@ -42,3 +44,19 @@ class TestElementsAPI(FixtureAPITestCase):
self
.
assertEqual
(
response
.
json
()[
'
name
'
],
'
Untitled (2)
'
)
self
.
vol
.
refresh_from_db
()
self
.
assertEqual
(
self
.
vol
.
name
,
'
Untitled (2)
'
)
def
test_get_transcriptions
(
self
):
self
.
page
.
transcriptions
.
all
().
delete
()
transcriptions
=
[]
for
i
in
range
(
10
):
transcriptions
.
append
(
self
.
page
.
transcriptions
.
create
(
source_id
=
self
.
src
.
id
,
type
=
TranscriptionType
.
Word
))
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
'
api:element-transcriptions
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
page
.
id
)}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
json
()[
'
results
'
]),
10
)
self
.
assertEqual
(
len
(
transcriptions
),
10
)
# Wrong transcription type
url
=
reverse
(
'
api:element-transcriptions
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
page
.
id
)})
url
+=
'
?type=potato
'
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
This diff is collapsed.
Click to expand it.
arkindex/project/api_v1.py
+
4
−
2
View file @
4ff58dfe
...
...
@@ -2,8 +2,9 @@ from django.urls import path
from
django.views.generic.base
import
RedirectView
from
arkindex.documents.api.elements
import
(
ElementsList
,
RelatedElementsList
,
ElementRetrieve
,
ElementPages
,
ElementSurfaces
,
CorpusList
,
CorpusRetrieve
,
CorpusPages
,
ActEdit
,
PageDetails
,
SurfaceDetails
,
ElementsList
,
RelatedElementsList
,
ElementRetrieve
,
ElementPages
,
ElementSurfaces
,
CorpusList
,
CorpusRetrieve
,
CorpusPages
,
ActEdit
,
PageDetails
,
SurfaceDetails
,
ElementTranscriptions
,
)
from
arkindex.documents.api.search
import
PageSearch
,
ActSearch
from
arkindex.documents.api.ml
import
ClassificationBulk
,
TranscriptionCreate
,
TranscriptionBulk
...
...
@@ -31,6 +32,7 @@ api = [
path
(
'
elements/
'
,
ElementsList
.
as_view
(),
name
=
'
elements
'
),
path
(
'
element/<uuid:pk>/
'
,
ElementRetrieve
.
as_view
(),
name
=
'
element-retrieve
'
),
path
(
'
element/<uuid:pk>/history/
'
,
ElementHistory
.
as_view
(),
name
=
'
element-history
'
),
path
(
'
element/<uuid:pk>/transcriptions/
'
,
ElementTranscriptions
.
as_view
(),
name
=
'
element-transcriptions
'
),
path
(
'
page/<uuid:pk>/
'
,
PageDetails
.
as_view
(),
name
=
'
page-details
'
),
path
(
'
surface/<uuid:pk>/
'
,
SurfaceDetails
.
as_view
(),
name
=
'
surface-details
'
),
path
(
'
corpus/
'
,
CorpusList
.
as_view
(),
name
=
'
corpus
'
),
...
...
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