From 352fb4f6ffead5d97a8d2ab8af8823af6264cbd3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 3 Oct 2023 10:39:24 +1100 Subject: [PATCH] Allow plugin list to be filtered by "sample" or "builtin" status (#5647) --- InvenTree/plugin/api.py | 27 +++++++++++++++++++ .../templates/js/translated/table_filters.js | 8 ++++++ 2 files changed, 35 insertions(+) diff --git a/InvenTree/plugin/api.py b/InvenTree/plugin/api.py index 1752704fd9..74ef2880e1 100644 --- a/InvenTree/plugin/api.py +++ b/InvenTree/plugin/api.py @@ -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 diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index 5ede626341..fa89534902 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -463,6 +463,14 @@ function getPluginTableFilters() { type: 'bool', title: '{% trans "Active" %}', }, + builtin: { + type: 'bool', + title: '{% trans "Builtin" %}', + }, + sample: { + type: 'bool', + title: '{% trans "Sample" %}', + }, }; }