search #8

Merged
cayop merged 3 commits from search into main 2024-10-09 16:04:01 +00:00
Showing only changes of commit e0258cbf02 - Show all commits

View file

@ -3,6 +3,7 @@ import json
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from django.shortcuts import Http404 from django.shortcuts import Http404
from django.db.models import Q
from dashboard.mixins import InventaryMixin, DetailsMixin from dashboard.mixins import InventaryMixin, DetailsMixin
from evidence.models import Annotation from evidence.models import Annotation
@ -65,6 +66,9 @@ class SearchView(InventaryMixin):
limit limit
) )
if not matches.size():
return self.search_hids(query, offset, limit)
annotations = [] annotations = []
for x in matches: for x in matches:
annotations.extend(self.get_annotations(x)) annotations.extend(self.get_annotations(x))
@ -83,3 +87,19 @@ class SearchView(InventaryMixin):
uuid=uuid uuid=uuid
).values_list("value", flat=True).distinct() ).values_list("value", flat=True).distinct()
def search_hids(self, query, offset, limit):
qry = Q()
for i in query[0].split(" "):
if i:
qry |= Q(value__startswith=i)
chids = Annotation.objects.filter(
type=Annotation.Type.SYSTEM,
owner=self.request.user.institution
).filter(
qry
).values_list("value", flat=True).distinct()
chids_page = chids[offset:offset+limit]
return [Device(id=x) for x in chids_page], chids.count()