Skip to content
Snippets Groups Projects
Commit 6d8275b1 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge get_queryset into list

parent 99a925de
No related branches found
No related tags found
1 merge request!18Transcription search
......@@ -52,12 +52,6 @@ class TranscriptionSearch(ListAPIView):
"""
serializer_class = SearchResultSerializer
def get_queryset(self):
query = self.request.query_params.get('q')
if not query:
return
return search_transcriptions(query)
def add_parents(self, results):
ids = [trans.id for trans in results]
all_parents = Document.objects.get_ascendings(*ids)
......@@ -66,17 +60,20 @@ class TranscriptionSearch(ListAPIView):
return results
def list(self, request):
queryset = self.get_queryset()
if queryset is None:
query = self.request.query_params.get('q')
if not query:
return
search_results = search_transcriptions(query)
if search_results is None:
return Response("", status=status.HTTP_204_NO_CONTENT)
# Handle pagination, if activated
page = self.paginate_queryset(queryset)
page = self.paginate_queryset(search_results)
if page is not None:
serializer = self.get_serializer(self.add_parents(page), many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(self.add_parents(queryset), many=True)
serializer = self.get_serializer(self.add_parents(search_results), many=True)
return Response(serializer.data)
......
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