From 7bd0c4a56307eca3ce48630ceccf1cc2cc556190 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 24 Feb 2025 12:25:03 +0100 Subject: [PATCH] fix search and pagination with search --- dashboard/templates/base.html | 4 ++-- dashboard/templates/pagination.html | 10 +++++----- dashboard/templates/unassigned_devices.html | 2 +- dashboard/templatetags/paginacion.py | 5 +++-- dashboard/views.py | 22 ++++++++++++++++++--- device/models.py | 2 +- evidence/mixin_parse.py | 5 +++++ evidence/parse.py | 3 +++ 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/dashboard/templates/base.html b/dashboard/templates/base.html index abe23a0..0ae59c8 100644 --- a/dashboard/templates/base.html +++ b/dashboard/templates/base.html @@ -194,10 +194,10 @@ {% endif %} -
+ {% csrf_token %}
- + diff --git a/dashboard/templates/pagination.html b/dashboard/templates/pagination.html index 7a20679..899a426 100644 --- a/dashboard/templates/pagination.html +++ b/dashboard/templates/pagination.html @@ -4,12 +4,12 @@
    {% if page_number > 1 %} @@ -24,7 +24,7 @@ {% if p == page_number or p == "..." %} href="#"> {% else %} - href="?page={{ p }}&limit={{ limit }}"> + href="?page={{ p }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}"> {% endif %} {{ p }} @@ -34,12 +34,12 @@ {% if page_number < total_pages %} diff --git a/dashboard/templates/unassigned_devices.html b/dashboard/templates/unassigned_devices.html index 8356019..25c1bec 100644 --- a/dashboard/templates/unassigned_devices.html +++ b/dashboard/templates/unassigned_devices.html @@ -86,7 +86,7 @@
- {% render_pagination page total_pages limit %} + {% render_pagination page total_pages limit search %}
{% endblock %} diff --git a/dashboard/templatetags/paginacion.py b/dashboard/templatetags/paginacion.py index 94ff5fc..6587483 100644 --- a/dashboard/templatetags/paginacion.py +++ b/dashboard/templatetags/paginacion.py @@ -3,7 +3,7 @@ from django import template register = template.Library() @register.inclusion_tag('pagination.html') -def render_pagination(page_number, total_pages, limit=10): +def render_pagination(page_number, total_pages, limit=10, search=None): """ Template tag for render pagination @@ -16,5 +16,6 @@ def render_pagination(page_number, total_pages, limit=10): return { 'page_number': page_number, 'total_pages': total_pages, - 'limit': limit + 'limit': limit, + "search": search, } diff --git a/dashboard/views.py b/dashboard/views.py index b4d51ee..01a8566 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -72,9 +72,20 @@ class SearchView(InventaryMixin): title = _("Search Devices") breadcrumb = "Devices / Search Devices" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + search_params = self.request.GET.urlencode(), + search = self.request.GET.get("search") + if search: + context.update({ + 'search_params': search_params, + 'search': search + }) + + return context + def get_devices(self, user, offset, limit): - post = dict(self.request.POST) - query = post.get("search") + query = dict(self.request.GET).get("search") if not query: return [], 0 @@ -85,6 +96,12 @@ class SearchView(InventaryMixin): offset, limit ) + count = search( + self.request.user.institution, + query[0], + 0, + 9999 + ).size() if not matches or not matches.size(): return self.search_hids(query, offset, limit) @@ -99,7 +116,6 @@ class SearchView(InventaryMixin): devices.append(dev) dev_id.append(dev.id) - count = matches.size() # TODO fix of pagination, the count is not correct return devices, count diff --git a/device/models.py b/device/models.py index 4a1f506..71d087a 100644 --- a/device/models.py +++ b/device/models.py @@ -336,7 +336,7 @@ class Device: FROM RankedProperties WHERE - row_num = 1; + row_num = 1 ORDER BY created DESC """.format( uuid=uuid.replace("-", ""), diff --git a/evidence/mixin_parse.py b/evidence/mixin_parse.py index 0fb6c36..3790281 100644 --- a/evidence/mixin_parse.py +++ b/evidence/mixin_parse.py @@ -19,6 +19,11 @@ class BuildMix: self.mac = "" self.type = "" self.version = "" + self.default = "" + self.algorithms = {} + if not self.uuid: + logger.error("snapshot without UUID. Software {}".format(self.json.get("software"))) + return self.get_details() self.generate_chids() diff --git a/evidence/parse.py b/evidence/parse.py index d73cff7..c625db3 100644 --- a/evidence/parse.py +++ b/evidence/parse.py @@ -55,6 +55,9 @@ class Build: if check: return + if not self.build.uuid: + return + self.index() self.create_annotations() if settings.DPP: