add search for hids
This commit is contained in:
parent
1abd846922
commit
e0258cbf02
|
@ -3,6 +3,7 @@ import json
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.edit import FormView
|
||||
from django.shortcuts import Http404
|
||||
from django.db.models import Q
|
||||
|
||||
from dashboard.mixins import InventaryMixin, DetailsMixin
|
||||
from evidence.models import Annotation
|
||||
|
@ -65,6 +66,9 @@ class SearchView(InventaryMixin):
|
|||
limit
|
||||
)
|
||||
|
||||
if not matches.size():
|
||||
return self.search_hids(query, offset, limit)
|
||||
|
||||
annotations = []
|
||||
for x in matches:
|
||||
annotations.extend(self.get_annotations(x))
|
||||
|
@ -83,3 +87,19 @@ class SearchView(InventaryMixin):
|
|||
uuid=uuid
|
||||
).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()
|
||||
|
|
Loading…
Reference in New Issue