Skip to content

Commit da73cb2

Browse files
committed
Add pagination to epss history
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 7857a24 commit da73cb2

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

vulnerabilities/templates/advisory_detail.html

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<div class="tabs is-boxed" id="tabs">
2727
<ul>
28-
<li class="is-active" data-tab="essentials">
28+
<li class="{% if not is_epss_tab_active %}is-active{% endif %}" data-tab="essentials">
2929
<a>
3030
<span>Essentials</span>
3131
</a>
@@ -55,7 +55,7 @@
5555
</li>
5656
{% endif %}
5757

58-
<li data-tab="epss">
58+
<li class="{% if is_epss_tab_active %}is-active{% endif %}" data-tab="epss">
5959
<a>
6060
<span>
6161
EPSS
@@ -100,7 +100,7 @@
100100
</ul>
101101
</div>
102102
<div id="tab-content">
103-
<div class="tab-div is-active" data-content="essentials">
103+
<div class="tab-div {% if not is_epss_tab_active %}is-active{% endif %}" data-content="essentials">
104104
<div class="tab-nested-div">
105105
<table class="table vcio-table width-100-pct mt-2">
106106
<tbody>
@@ -458,7 +458,7 @@
458458
{% endfor %}
459459
</div>
460460

461-
<div class="tab-div content" data-content="epss">
461+
<div class="tab-div content {% if is_epss_tab_active %}is-active{% endif %}" data-content="epss">
462462
{% if epss_data %}
463463
<div class="has-text-weight-bold tab-nested-div ml-1 mb-1 mt-1">
464464
Exploit Prediction Scoring System (EPSS)
@@ -549,7 +549,7 @@
549549
<div id="epss-chart" style="width:100%; height:260px;"></div>
550550
</div>
551551

552-
<div id="epss-history-table-wrap" style="display:none; margin-top:2rem;">
552+
<div id="epss-history-table-wrap" {% if not is_epss_tab_active %}style="display:none; margin-top:2rem;"{% else %}style="margin-top:2rem;"{% endif %}>
553553
<div class="has-text-weight-bold tab-nested-div ml-1 mb-3">
554554
EPSS History Table
555555
</div>
@@ -571,6 +571,22 @@
571571
{% endfor %}
572572
</tbody>
573573
</table>
574+
575+
{% if epss_page_obj and epss_page_obj.has_other_pages %}
576+
<nav class="pagination is-small is-centered mt-4" role="navigation" aria-label="pagination">
577+
{% if epss_page_obj.has_previous %}
578+
<a class="pagination-previous" href="?epss_page={{ epss_page_obj.previous_page_number }}">Newer</a>
579+
{% else %}
580+
<a class="pagination-previous" disabled>Newer</a>
581+
{% endif %}
582+
583+
{% if epss_page_obj.has_next %}
584+
<a class="pagination-next" href="?epss_page={{ epss_page_obj.next_page_number }}">Older</a>
585+
{% else %}
586+
<a class="pagination-next" disabled>Older</a>
587+
{% endif %}
588+
</nav>
589+
{% endif %}
574590
</div>
575591
{% endif %}
576592
{% else %}

vulnerabilities/views.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from django.db.models import Max
2727
from django.db.models import OuterRef
2828
from django.db.models import Prefetch
29+
from django.core.paginator import Paginator
2930
from django.db.models import Q
3031
from django.db.models.functions import Cast
3132
from django.db.models.functions import TruncDate
@@ -769,20 +770,25 @@ def add_ssvc(ssvc):
769770
max_score=Max(Cast("value", FloatField())),
770771
max_percentile=Max(Cast("scoring_elements", FloatField())),
771772
)
772-
.order_by("-pub_date")[:30]
773+
.order_by("-pub_date")
773774
)
775+
776+
paginator = Paginator(epss_scores_queryset, 30)
777+
epss_page = self.request.GET.get("epss_page", 1)
778+
epss_page_obj = paginator.get_page(epss_page)
774779

775780
epss_history_data = [
776781
{
777782
"score": record["max_score"],
778783
"percentile": record["max_percentile"],
779784
"published_at": record["pub_date"],
780785
}
781-
for record in epss_scores_queryset
786+
for record in epss_page_obj.object_list
782787
]
783788
epss_history_data.reverse()
784789
else:
785790
epss_history_data = []
791+
epss_page_obj = None
786792

787793
context.update(
788794
{
@@ -796,6 +802,8 @@ def add_ssvc(ssvc):
796802
"status": advisory.get_status_label,
797803
"epss_data": epss_data,
798804
"epss_history_data": epss_history_data,
805+
"epss_page_obj": epss_page_obj,
806+
"is_epss_tab_active": "epss_page" in self.request.GET,
799807
}
800808
)
801809
return context

0 commit comments

Comments
 (0)