mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Plugin list API filters
- Filter by "active" status - Filter by "mixin" support
This commit is contained in:
parent
6aeb7d723d
commit
26f32a0ce8
@ -7,9 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.urls import include, re_path
|
from django.urls import include, re_path
|
||||||
|
|
||||||
from rest_framework import generics
|
from rest_framework import filters, generics, permissions, status
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework import permissions
|
|
||||||
from rest_framework.exceptions import NotFound
|
from rest_framework.exceptions import NotFound
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@ -35,6 +33,35 @@ class PluginList(generics.ListAPIView):
|
|||||||
serializer_class = PluginSerializers.PluginConfigSerializer
|
serializer_class = PluginSerializers.PluginConfigSerializer
|
||||||
queryset = PluginConfig.objects.all()
|
queryset = PluginConfig.objects.all()
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
|
params = self.request.query_params
|
||||||
|
|
||||||
|
# Filter plugins which support a given mixin
|
||||||
|
mixin = params.get('mixin', None)
|
||||||
|
|
||||||
|
if mixin:
|
||||||
|
matches = []
|
||||||
|
|
||||||
|
for result in queryset:
|
||||||
|
if mixin in result.mixins().keys():
|
||||||
|
matches.append(result.pk)
|
||||||
|
|
||||||
|
queryset = queryset.filter(pk__in=matches)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend,
|
||||||
|
filters.SearchFilter,
|
||||||
|
filters.OrderingFilter,
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_fields = [
|
||||||
|
'active',
|
||||||
|
]
|
||||||
|
|
||||||
ordering_fields = [
|
ordering_fields = [
|
||||||
'key',
|
'key',
|
||||||
'name',
|
'name',
|
||||||
|
Loading…
Reference in New Issue
Block a user