17 lines
500 B
Python
17 lines
500 B
Python
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
|
|
ctx.update(bds_search.search(q.split()))
|
|
return ctx
|