@@ -121,6 +121,7 @@ def filter_queryset(self, queryset):
121121 for name , value in self .form .cleaned_data .items ():
122122 field_name = self .filters [name ].field_name
123123 if value == self .empty_value :
124+ print (name , value )
124125 queryset = queryset .filter (** {f"{ field_name } __in" : EMPTY_VALUES })
125126 elif value == self .other_value and hasattr (queryset , "less_common" ):
126127 return queryset .less_common (name )
@@ -278,6 +279,26 @@ def filter(self, qs, value):
278279 return qs
279280
280281
282+ class RelationMatchTypeFilter (django_filters .ChoiceFilter ):
283+ def __init__ (self , * args , ** kwargs ):
284+ kwargs ["choices" ] = (
285+ ("" , "All" ),
286+ ("none" , "No match" ),
287+ ("any" , "Any match" ),
288+ ("java_to_class" , "java to class" ),
289+ ("path" , "path" ),
290+ ("sha1" , "sha1" ),
291+ )
292+ super ().__init__ (* args , ** kwargs )
293+
294+ def filter (self , qs , value ):
295+ if value == "none" :
296+ return qs .has_no_relation ()
297+ elif value == "any" :
298+ return qs .has_relation ()
299+ return super ().filter (qs , value )
300+
301+
281302class ResourceFilterSet (FilterSetUtilsMixin , django_filters .FilterSet ):
282303 search = django_filters .CharFilter (
283304 label = "Search" ,
@@ -297,6 +318,7 @@ class ResourceFilterSet(FilterSetUtilsMixin, django_filters.FilterSet):
297318 "mime_type" ,
298319 "tag" ,
299320 "compliance_alert" ,
321+ "related_from__match_type" ,
300322 ],
301323 )
302324 license_key = JSONContainsFilter (
@@ -311,6 +333,10 @@ class ResourceFilterSet(FilterSetUtilsMixin, django_filters.FilterSet):
311333 choices = CodebaseResource .Compliance .choices + [("EMPTY" , "EMPTY" )]
312334 )
313335 in_package = InPackageFilter (label = "In a Package" )
336+ relation_match_type = RelationMatchTypeFilter (
337+ label = "Relation match type" ,
338+ field_name = "related_from__match_type" ,
339+ )
314340
315341 class Meta :
316342 model = CodebaseResource
@@ -341,8 +367,7 @@ class Meta:
341367 "emails" ,
342368 "urls" ,
343369 "in_package" ,
344- # CodebaseRelation
345- "related_from__match_type" ,
370+ "relation_match_type" ,
346371 ]
347372
348373 @classmethod
0 commit comments