Skip to content

Commit 7a6c4de

Browse files
committed
Fix a bug related to rules paginator
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent e4699e9 commit 7a6c4de

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

vulnerabilities/templates/detection_rules.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{ page_obj.paginator.count|intcomma }} results
1919
</div>
2020
{% if is_paginated %}
21-
{% include 'includes/pagination.html' with page_obj=page_obj %}
21+
{% include 'includes/rules_pagination.html' with page_obj=page_obj %}
2222
{% endif %}
2323
</div>
2424
</section>
@@ -58,7 +58,7 @@
5858

5959

6060
{% if is_paginated %}
61-
{% include 'includes/pagination.html' with page_obj=page_obj %}
61+
{% include 'includes/rules_pagination.html' with page_obj=page_obj %}
6262
{% endif %}
6363
</section>
6464

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<nav class="pagination is-centered is-small" aria-label="pagination">
2+
{% if page_obj.has_previous %}
3+
<a href="{% querystring page=page_obj.previous_page_number %}" class="pagination-previous">Previous</a>
4+
{% else %}
5+
<a class="pagination-previous">Previous</a>
6+
{% endif %}
7+
8+
{% if page_obj.has_next %}
9+
<a href="{% querystring page=page_obj.next_page_number %}" class="pagination-next">Next</a>
10+
{% else %}
11+
<a class="pagination-next">Next</a>
12+
{% endif %}
13+
14+
<ul class="pagination-list">
15+
{% for page_num in elided_page_range %}
16+
{% if page_num == page_obj.paginator.ELLIPSIS %}
17+
<li>
18+
<span class="pagination-ellipsis">&hellip;</span>
19+
</li>
20+
{% elif page_num == page_obj.number %}
21+
<li>
22+
<a class="pagination-link is-current"
23+
aria-label="Page {{ page_num }}"
24+
aria-current="page">{{ page_num }}
25+
</a>
26+
</li>
27+
{% else %}
28+
<li>
29+
<a href="{% querystring page=page_num %}"
30+
class="pagination-link"
31+
aria-label="Goto page {{ page_num }}">{{ page_num }}</a>
32+
</li>
33+
{% endif %}
34+
{% endfor %}
35+
</ul>
36+
37+
</nav>

vulnerabilities/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.db.models import F
2020
from django.db.models import Prefetch
2121
from django.db.models import Q
22+
from django.http import QueryDict
2223
from django.http.response import Http404
2324
from django.shortcuts import get_object_or_404
2425
from django.shortcuts import redirect
@@ -152,7 +153,10 @@ def get_context_data(self, **kwargs):
152153
context = super().get_context_data(**kwargs)
153154
request_query = self.request.GET
154155
context["detection_search_form"] = DetectionRuleSearchForm(request_query)
155-
context["search"] = request_query.get("search")
156+
page_obj = context["page_obj"]
157+
context["elided_page_range"] = page_obj.paginator.get_elided_page_range(
158+
page_obj.number, on_each_side=2, on_ends=1
159+
)
156160
return context
157161

158162
def get_queryset(self):

0 commit comments

Comments
 (0)