pedagogy: search index for uvs and search api

This commit is contained in:
2019-06-18 21:41:11 +02:00
parent 358a625cc4
commit 061320a5df
4 changed files with 86 additions and 0 deletions

View File

@ -32,6 +32,7 @@ from django.views.generic import (
View,
)
from django.core.urlresolvers import reverse_lazy
from django.utils import html
from core.views import (
DetailFormView,
@ -41,6 +42,8 @@ from core.views import (
CanEditPropMixin,
)
from haystack.query import SearchQuerySet
from pedagogy.forms import UVForm, UVCommentForm
from pedagogy.models import UV, UVComment
@ -144,6 +147,27 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
ordering = ["code"]
template_name = "pedagogy/guide.jinja"
def get_queryset(self):
query = self.request.GET.get("query", None)
if not query:
return super(UVListView, self).get_queryset()
try:
queryset = (
SearchQuerySet()
.models(self.model)
.autocomplete(auto=html.escape(query))
)
except TypeError:
return self.model.objects.none()
return (
super(UVListView, self)
.get_queryset()
.filter(id__in=([o.object.id for o in queryset]))
)
class UVCommentReportCreateView(CreateView):
"""