kpsul/bds/views.py

24 lines
653 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
class AutocompleteView(TemplateView):
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
class Home(TemplateView):
template_name = "bds/home.html"