mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow plugin list to be filtered by "sample" or "builtin" status (#5647)
This commit is contained in:
parent
6a48eaeec8
commit
352fb4f6ff
@ -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
|
||||
|
@ -463,6 +463,14 @@ function getPluginTableFilters() {
|
||||
type: 'bool',
|
||||
title: '{% trans "Active" %}',
|
||||
},
|
||||
builtin: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Builtin" %}',
|
||||
},
|
||||
sample: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Sample" %}',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user