mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
pedagogy: handle one letter search
This commit is contained in:
parent
22c028af11
commit
e21821ace5
@ -162,6 +162,7 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
queryset = super(UVListView, self).get_queryset()
|
||||||
search = self.request.GET.get("search", None)
|
search = self.request.GET.get("search", None)
|
||||||
|
|
||||||
additional_filters = {}
|
additional_filters = {}
|
||||||
@ -178,11 +179,17 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
|||||||
else:
|
else:
|
||||||
additional_filters["semester"] = semester
|
additional_filters["semester"] = semester
|
||||||
|
|
||||||
|
queryset = queryset.filter(**additional_filters)
|
||||||
if not search:
|
if not search:
|
||||||
return super(UVListView, self).get_queryset().filter(**additional_filters)
|
return queryset
|
||||||
|
|
||||||
|
if len(search) == 1:
|
||||||
|
# It's a search with only one letter
|
||||||
|
# Hastack doesn't work well with only one letter
|
||||||
|
return queryset.filter(code__startswith=search)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
queryset = (
|
qs = (
|
||||||
SearchQuerySet()
|
SearchQuerySet()
|
||||||
.models(self.model)
|
.models(self.model)
|
||||||
.autocomplete(auto=html.escape(search))
|
.autocomplete(auto=html.escape(search))
|
||||||
@ -190,12 +197,7 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
return self.model.objects.none()
|
return self.model.objects.none()
|
||||||
|
|
||||||
return (
|
return queryset.filter(id__in=([o.object.id for o in qs]))
|
||||||
super(UVListView, self)
|
|
||||||
.get_queryset()
|
|
||||||
.filter(id__in=([o.object.id for o in queryset]))
|
|
||||||
.filter(**additional_filters)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UVCommentReportCreateView(CreateView):
|
class UVCommentReportCreateView(CreateView):
|
||||||
|
Loading…
Reference in New Issue
Block a user