Allow plugin list to be filtered by "sample" or "builtin" status (#5647)

This commit is contained in:
Oliver 2023-10-03 10:39:24 +11:00 committed by GitHub
parent 6a48eaeec8
commit 352fb4f6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import plugin.serializers as PluginSerializers
from common.api import GlobalSettingsPermissions
from InvenTree.api import MetadataView
from InvenTree.filters import SEARCH_ORDER_FILTER
from InvenTree.helpers import str2bool
from InvenTree.mixins import (CreateAPI, ListAPI, RetrieveUpdateAPI,
RetrieveUpdateDestroyAPI, UpdateAPI)
from InvenTree.permissions import IsSuperuser
@ -56,6 +57,32 @@ class PluginList(ListAPI):
queryset = queryset.filter(pk__in=matches)
# Filter queryset by 'builtin' flag
# We cannot do this using normal filters as it is not a database field
if 'builtin' in params:
builtin = str2bool(params['builtin'])
matches = []
for result in queryset:
if result.is_builtin() == builtin:
matches.append(result.pk)
queryset = queryset.filter(pk__in=matches)
# Filter queryset by 'sample' flag
# We cannot do this using normal filters as it is not a database field
if 'sample' in params:
sample = str2bool(params['sample'])
matches = []
for result in queryset:
if result.is_sample() == sample:
matches.append(result.pk)
queryset = queryset.filter(pk__in=matches)
return queryset
filter_backends = SEARCH_ORDER_FILTER

View File

@ -463,6 +463,14 @@ function getPluginTableFilters() {
type: 'bool',
title: '{% trans "Active" %}',
},
builtin: {
type: 'bool',
title: '{% trans "Builtin" %}',
},
sample: {
type: 'bool',
title: '{% trans "Sample" %}',
},
};
}