Simple search in api
[wolnelektury.git] / src / search / api / views.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from rest_framework.generics import ListAPIView
5 from rest_framework.response import Response
6 from rest_framework.views import APIView
7 from search.views import get_hints
8 from search.forms import SearchFilters
9
10
11 class HintView(APIView):
12     def get(self, request):
13         term = request.query_params.get('q')
14         hints = get_hints(term, request.user)
15         return Response(hints)
16
17
18 class SearchView(APIView):
19     def get(self, request):
20         term = self.request.query_params.get('q')
21         f = SearchFilters({'q': term})
22         r = {}
23         if f.is_valid():
24             r = f.results()
25         return Response(r)
26
27 class BookSearchView(ListAPIView):
28     def get_queryset(self, request):
29         term = self.request.query_params.get('q')
30
31 class TextSearchView(ListAPIView):
32     def get_queryset(self, request):
33         term = self.request.query_params.get('q')