mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Allow plugin list to be filtered by "sample" or "builtin" status (#5647)
This commit is contained in:
		| @@ -11,6 +11,7 @@ import plugin.serializers as PluginSerializers | |||||||
| from common.api import GlobalSettingsPermissions | from common.api import GlobalSettingsPermissions | ||||||
| from InvenTree.api import MetadataView | from InvenTree.api import MetadataView | ||||||
| from InvenTree.filters import SEARCH_ORDER_FILTER | from InvenTree.filters import SEARCH_ORDER_FILTER | ||||||
|  | from InvenTree.helpers import str2bool | ||||||
| from InvenTree.mixins import (CreateAPI, ListAPI, RetrieveUpdateAPI, | from InvenTree.mixins import (CreateAPI, ListAPI, RetrieveUpdateAPI, | ||||||
|                               RetrieveUpdateDestroyAPI, UpdateAPI) |                               RetrieveUpdateDestroyAPI, UpdateAPI) | ||||||
| from InvenTree.permissions import IsSuperuser | from InvenTree.permissions import IsSuperuser | ||||||
| @@ -56,6 +57,32 @@ class PluginList(ListAPI): | |||||||
|  |  | ||||||
|             queryset = queryset.filter(pk__in=matches) |             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 |         return queryset | ||||||
|  |  | ||||||
|     filter_backends = SEARCH_ORDER_FILTER |     filter_backends = SEARCH_ORDER_FILTER | ||||||
|   | |||||||
| @@ -463,6 +463,14 @@ function getPluginTableFilters() { | |||||||
|             type: 'bool', |             type: 'bool', | ||||||
|             title: '{% trans "Active" %}', |             title: '{% trans "Active" %}', | ||||||
|         }, |         }, | ||||||
|  |         builtin: { | ||||||
|  |             type: 'bool', | ||||||
|  |             title: '{% trans "Builtin" %}', | ||||||
|  |         }, | ||||||
|  |         sample: { | ||||||
|  |             type: 'bool', | ||||||
|  |             title: '{% trans "Sample" %}', | ||||||
|  |         }, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user