fix search and pagination with search
This commit is contained in:
parent
29f08a633b
commit
7bd0c4a563
|
@ -194,10 +194,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<form method="post" action="{% url 'dashboard:search' %}">
|
<form method="get" action="{% url 'dashboard:search' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="input-group rounded">
|
<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">
|
<span class="input-group-text border-0" id="search-addon">
|
||||||
<i class="fas fa-search"></i>
|
<i class="fas fa-search"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{% if page_number > 1 %}
|
{% if page_number > 1 %}
|
||||||
<li class="previous">
|
<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>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="previous">
|
<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' %}
|
{% trans 'Previous' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
{% if p == page_number or p == "..." %}
|
{% if p == page_number or p == "..." %}
|
||||||
href="#">
|
href="#">
|
||||||
{% else %}
|
{% else %}
|
||||||
href="?page={{ p }}&limit={{ limit }}">
|
href="?page={{ p }}&limit={{ limit }}{% if search %}&search={{ search }}{% endif %}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ p }}
|
{{ p }}
|
||||||
</a>
|
</a>
|
||||||
|
@ -34,12 +34,12 @@
|
||||||
|
|
||||||
{% if page_number < total_pages %}
|
{% if page_number < total_pages %}
|
||||||
<li class="previous">
|
<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' %}
|
{% trans 'Next' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="previous">
|
<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>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{% render_pagination page total_pages limit %}
|
{% render_pagination page total_pages limit search %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django import template
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@register.inclusion_tag('pagination.html')
|
@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
|
Template tag for render pagination
|
||||||
|
|
||||||
|
@ -16,5 +16,6 @@ def render_pagination(page_number, total_pages, limit=10):
|
||||||
return {
|
return {
|
||||||
'page_number': page_number,
|
'page_number': page_number,
|
||||||
'total_pages': total_pages,
|
'total_pages': total_pages,
|
||||||
'limit': limit
|
'limit': limit,
|
||||||
|
"search": search,
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,20 @@ class SearchView(InventaryMixin):
|
||||||
title = _("Search Devices")
|
title = _("Search Devices")
|
||||||
breadcrumb = "Devices / 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):
|
def get_devices(self, user, offset, limit):
|
||||||
post = dict(self.request.POST)
|
query = dict(self.request.GET).get("search")
|
||||||
query = post.get("search")
|
|
||||||
|
|
||||||
if not query:
|
if not query:
|
||||||
return [], 0
|
return [], 0
|
||||||
|
@ -85,6 +96,12 @@ class SearchView(InventaryMixin):
|
||||||
offset,
|
offset,
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
|
count = search(
|
||||||
|
self.request.user.institution,
|
||||||
|
query[0],
|
||||||
|
0,
|
||||||
|
9999
|
||||||
|
).size()
|
||||||
|
|
||||||
if not matches or not matches.size():
|
if not matches or not matches.size():
|
||||||
return self.search_hids(query, offset, limit)
|
return self.search_hids(query, offset, limit)
|
||||||
|
@ -99,7 +116,6 @@ class SearchView(InventaryMixin):
|
||||||
devices.append(dev)
|
devices.append(dev)
|
||||||
dev_id.append(dev.id)
|
dev_id.append(dev.id)
|
||||||
|
|
||||||
count = matches.size()
|
|
||||||
# TODO fix of pagination, the count is not correct
|
# TODO fix of pagination, the count is not correct
|
||||||
return devices, count
|
return devices, count
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ class Device:
|
||||||
FROM
|
FROM
|
||||||
RankedProperties
|
RankedProperties
|
||||||
WHERE
|
WHERE
|
||||||
row_num = 1;
|
row_num = 1
|
||||||
ORDER BY created DESC
|
ORDER BY created DESC
|
||||||
""".format(
|
""".format(
|
||||||
uuid=uuid.replace("-", ""),
|
uuid=uuid.replace("-", ""),
|
||||||
|
|
|
@ -19,6 +19,11 @@ class BuildMix:
|
||||||
self.mac = ""
|
self.mac = ""
|
||||||
self.type = ""
|
self.type = ""
|
||||||
self.version = ""
|
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.get_details()
|
||||||
self.generate_chids()
|
self.generate_chids()
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,9 @@ class Build:
|
||||||
if check:
|
if check:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.build.uuid:
|
||||||
|
return
|
||||||
|
|
||||||
self.index()
|
self.index()
|
||||||
self.create_annotations()
|
self.create_annotations()
|
||||||
if settings.DPP:
|
if settings.DPP:
|
||||||
|
|
Loading…
Reference in a new issue