@@ -1234,6 +1234,16 @@ def license_detections_count(self):
12341234 """Return the number of license detections in this project."""
12351235 return self .discoveredlicenses .count ()
12361236
1237+ @cached_property
1238+ def package_compliance_alert_count (self ):
1239+ """Return the number of packages related to this project which have."""
1240+ return self .discoveredpackages .has_compliance_alert ().count ()
1241+
1242+ @cached_property
1243+ def license_compliance_alert_count (self ):
1244+ """Return the number of packages related to this project which have."""
1245+ return self .discoveredlicenses .has_compliance_alert ().count ()
1246+
12371247 @cached_property
12381248 def message_count (self ):
12391249 """Return the number of messages related to this project."""
@@ -2156,6 +2166,17 @@ class Compliance(models.TextChoices):
21562166 class Meta :
21572167 abstract = True
21582168
2169+ @property
2170+ def has_compliance_alert (self ):
2171+ """
2172+ Returns True if this instance has a compliance alert of `ERROR`
2173+ for it's respective license_expression fields.
2174+ """
2175+ if self .compliance_alert == self .Compliance .ERROR :
2176+ return True
2177+
2178+ return False
2179+
21592180 @classmethod
21602181 def from_db (cls , db , field_names , values ):
21612182 """
@@ -2710,8 +2731,16 @@ def vulnerable(self):
27102731 return self .filter (~ Q (affected_by_vulnerabilities__in = EMPTY_VALUES ))
27112732
27122733
2734+ class ComplianceAlertQuerySetMixin :
2735+ def has_compliance_alert (self ):
2736+ return self .filter (Q (compliance_alert__exact = CodebaseResource .Compliance .ERROR ))
2737+
2738+
27132739class DiscoveredPackageQuerySet (
2714- VulnerabilityQuerySetMixin , PackageURLQuerySetMixin , ProjectRelatedQuerySet
2740+ VulnerabilityQuerySetMixin ,
2741+ ComplianceAlertQuerySetMixin ,
2742+ PackageURLQuerySetMixin ,
2743+ ProjectRelatedQuerySet ,
27152744):
27162745 def order_by_purl (self ):
27172746 """Order by Package URL fields."""
@@ -3485,7 +3514,10 @@ def as_spdx(self):
34853514 )
34863515
34873516
3488- class DiscoveredLicenseQuerySet (ProjectRelatedQuerySet ):
3517+ class DiscoveredLicenseQuerySet (
3518+ ComplianceAlertQuerySetMixin ,
3519+ ProjectRelatedQuerySet ,
3520+ ):
34893521 def order_by_count_and_expression (self ):
34903522 """Order by detection count and license expression (identifer) fields."""
34913523 return self .order_by ("-detection_count" , "identifier" )
@@ -3550,7 +3582,6 @@ class DiscoveredLicense(
35503582 """
35513583 A project's Discovered Licenses are the unique License Detection objects
35523584 discovered in the code under analysis.
3553-
35543585 """
35553586
35563587 license_expression_field = "license_expression"
0 commit comments