kpsul/bds/views.py

25 lines
735 B
Python
Raw Normal View History

2020-06-05 17:02:16 +02:00
from django.http import Http404
from django.views.generic import TemplateView
from bds.autocomplete import bds_search
2020-06-07 21:01:54 +02:00
from bds.mixins import StaffRequiredMixin
2020-06-05 17:02:16 +02:00
2020-06-07 21:01:54 +02:00
class AutocompleteView(StaffRequiredMixin, TemplateView):
2020-06-05 17:02:16 +02:00
template_name = "bds/search_results.html"
def get_context_data(self, *args, **kwargs):
ctx = super().get_context_data(*args, **kwargs)
if "q" not in self.request.GET:
raise Http404
q = self.request.GET["q"]
ctx["q"] = q
2020-06-07 20:58:33 +02:00
results = bds_search.search(q.split())
ctx.update(results)
ctx["total"] = sum((len(r) for r in results.values()))
2020-06-05 17:02:16 +02:00
return ctx
2020-06-07 20:58:33 +02:00
2020-06-07 21:01:54 +02:00
class Home(StaffRequiredMixin, TemplateView):
2020-06-07 20:58:33 +02:00
template_name = "bds/home.html"