Skip to content

Commit c9bfbf2

Browse files
committed
adjust active filter rendering
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent b730fe4 commit c9bfbf2

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

product_portfolio/filters.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ class BaseProductRelationFilterSet(DataspacedFilterSet):
264264
field_name="licenses__usage_policy__compliance_alert",
265265
distinct=True,
266266
)
267+
policy_rule = django_filters.CharFilter(
268+
label=_("Policy rule"),
269+
method="filter_by_policy_rule",
270+
)
271+
272+
def filter_by_policy_rule(self, queryset, name, value):
273+
"""Filter packages that triggered the given policy rule type."""
274+
if queryset.model is not ProductPackage:
275+
return queryset.none()
276+
handler = RULE_REGISTRY.get(value)
277+
if not handler:
278+
return queryset
279+
return handler.filter_queryset(queryset).distinct()
267280

268281
@staticmethod
269282
def filter_object_type(queryset, name, value):
@@ -408,7 +421,6 @@ class ProductPackageFilterSet(BaseProductRelationFilterSet):
408421
field_name="package__usage_policy__compliance_alert",
409422
distinct=True,
410423
)
411-
policy_rule = django_filters.CharFilter(method="filter_by_policy_rule")
412424

413425
class Meta:
414426
model = ProductPackage
@@ -424,13 +436,6 @@ class Meta:
424436
"exploitability",
425437
]
426438

427-
def filter_by_policy_rule(self, queryset, name, value):
428-
"""Filter packages that triggered the given policy rule type."""
429-
handler = RULE_REGISTRY.get(value)
430-
if not handler:
431-
return queryset
432-
return handler.filter_queryset(queryset).distinct()
433-
434439
def __init__(self, *args, **kwargs):
435440
super().__init__(*args, **kwargs)
436441
self.filters["vulnerability_analyses__state"].extra["null_label"] = "(No values)"

product_portfolio/templates/product_portfolio/compliance/compliance_panels.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h5 class="modal-title fs-6 fw-medium" id="policy-rules-modal-label">{% trans "P
9595
</td>
9696
<td class="text-body-secondary small">{{ violation.rule_description }}</td>
9797
<td class="text-end">
98-
<a href="{{ product_url }}?inventory-object_type=package&amp;inventory-policy_rule={{ violation.rule_type }}#inventory"
98+
<a href="{{ product_url }}?inventory-policy_rule={{ violation.rule_type }}#inventory"
9999
class="text-decoration-none">
100100
{{ violation.violation_count }}
101101
</a>

0 commit comments

Comments
 (0)