From d63e292cecc23e7ead085d15d2320ac3b94d1d8e Mon Sep 17 00:00:00 2001 From: vrigal <rigal@teklia.com> Date: Mon, 2 Dec 2019 10:57:23 +0100 Subject: [PATCH] Add structure metadata filter in filtered ListElement endpoints --- arkindex/documents/api/elements.py | 44 +++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/arkindex/documents/api/elements.py b/arkindex/documents/api/elements.py index c2fb0fd4cb..258de783a6 100644 --- a/arkindex/documents/api/elements.py +++ b/arkindex/documents/api/elements.py @@ -8,7 +8,7 @@ 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, MetaData, Classification, ClassificationState, Transcription, Region @@ -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') -- GitLab