fix search and pagination with search
This commit is contained in:
parent
29f08a633b
commit
7bd0c4a563
|
@ -194,10 +194,10 @@
|
|||
{% endif %}
|
||||
</h1>
|
||||
|
||||
<form method="post" action="{% url 'dashboard:search' %}">
|
||||
<form method="get" action="{% url 'dashboard:search' %}">
|
||||
{% csrf_token %}
|
||||
<div class="input-group rounded">
|
||||
<input type="search" name="search" class="form-control rounded" placeholder="Search your device..." aria-label="Search" aria-describedby="search-addon" />
|
||||
<input type="search" name="search" class="form-control rounded" {% if search %}value="{{ search }}" {% endif %}placeholder="Search your device..." aria-label="Search" aria-describedby="search-addon" />
|
||||
<span class="input-group-text border-0" id="search-addon">
|
||||
<i class="fas fa-search"></i>
|
||||
</span>
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
<ul class="pagination">
|
||||
{% if page_number > 1 %}
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
|
||||
{% trans 'Previous' %}
|
||||
</a>
|
||||
</li>
|
||||
|
@ -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 }}
|
||||
</a>
|
||||
|
@ -34,12 +34,12 @@
|
|||
|
||||
{% if page_number < total_pages %}
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
|
||||
{% trans 'Next' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
|
||||
»
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{% render_pagination page total_pages limit %}
|
||||
{% render_pagination page total_pages limit search %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ class Device:
|
|||
FROM
|
||||
RankedProperties
|
||||
WHERE
|
||||
row_num = 1;
|
||||
row_num = 1
|
||||
ORDER BY created DESC
|
||||
""".format(
|
||||
uuid=uuid.replace("-", ""),
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ class Build:
|
|||
if check:
|
||||
return
|
||||
|
||||
if not self.build.uuid:
|
||||
return
|
||||
|
||||
self.index()
|
||||
self.create_annotations()
|
||||
if settings.DPP:
|
||||
|
|
Loading…
Reference in a new issue