mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
pedagogy: search index for uvs and search api
This commit is contained in:
@ -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):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user