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

Add structure metadata filter in filtered ListElement endpoints

parent 56bbc98f
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,9 @@ from rest_framework.generics import (
)
from rest_framework import status, response
from rest_framework.response import Response
from arkindex_common.enums import TranscriptionType
from arkindex_common.enums import TranscriptionType, MetaType
from arkindex.documents.models import (
Corpus, Element, ElementPath, Right,
Corpus, Element, ElementPath, Right, MetaData,
Classification, ClassificationState, Transcription, Region
)
from arkindex.documents.serializers.elements import (
......@@ -115,6 +115,13 @@ class ElementsList(CorpusACLMixin, ListAPIView):
'schema': {
'type': 'boolean',
}
},
{
'name': 'structure',
'in': 'query',
'description': 'Filter elements by a structural metadata.',
'required': False,
'schema': {'type': 'string'},
}
]
}
......@@ -138,6 +145,13 @@ class ElementsList(CorpusACLMixin, ListAPIView):
if only_folder is not None:
filters['type__folder'] = only_folder.lower() not in ('false', '0')
structure_param = self.request.query_params.get('structure')
if structure_param is not None:
filters['metadatas__in'] = MetaData.objects.filter(
type=MetaType.Structure,
value__contains=structure_param
)
if 'corpus' in self.request.query_params:
try:
corpus_id = UUID(self.request.query_params['corpus'])
......@@ -372,6 +386,13 @@ class ElementParents(ListAPIView):
'schema': {
'type': 'boolean',
}
},
{
'name': 'structure',
'in': 'query',
'description': 'Filter elements by a structural metadata.',
'required': False,
'schema': {'type': 'string'},
}
]
}
......@@ -396,6 +417,13 @@ class ElementParents(ListAPIView):
if only_folder is not None:
filters['type__folder'] = only_folder.lower() not in ('false', '0')
structure_param = self.request.query_params.get('structure')
if structure_param is not None:
filters['metadatas__in'] = MetaData.objects.filter(
type=MetaType.Structure,
value__contains=structure_param
)
recursive_param = self.request.query_params.get('recursive')
prefetch_related_lookups = ('zone__image__server', 'corpus', 'type')
......@@ -510,6 +538,13 @@ class ElementChildren(ListAPIView):
'schema': {
'type': 'boolean',
}
},
{
'name': 'structure',
'in': 'query',
'description': 'Filter elements by a structural metadata.',
'required': False,
'schema': {'type': 'string'},
}
]
}
......@@ -534,6 +569,13 @@ class ElementChildren(ListAPIView):
if only_folder is not None:
filters['type__folder'] = only_folder.lower() not in ('false', '0')
structure_param = self.request.query_params.get('structure')
if structure_param is not None:
filters['metadatas__in'] = MetaData.objects.filter(
type=MetaType.Structure,
value__contains=structure_param
)
recursive_param = self.request.query_params.get('recursive')
prefetch_related_lookups = ('zone__image__server', 'corpus', 'type')
......
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