diff --git a/apps/applications/api/application.py b/apps/applications/api/application.py index 1933f6280..009376333 100644 --- a/apps/applications/api/application.py +++ b/apps/applications/api/application.py @@ -5,7 +5,6 @@ from orgs.mixins.api import OrgBulkModelViewSet from ..hands import IsOrgAdminOrAppUser from .. import serializers from ..models import Application -from applications.filters import ApplicationFilter __all__ = ['ApplicationViewSet'] @@ -13,7 +12,11 @@ __all__ = ['ApplicationViewSet'] class ApplicationViewSet(OrgBulkModelViewSet): model = Application - filterset_class = ApplicationFilter + filterset_fields = { + 'name': ['exact'], + 'category': ['exact'], + 'type': ['exact', 'in'], + } search_fields = ('name', 'type', 'category') permission_classes = (IsOrgAdminOrAppUser,) serializer_class = serializers.ApplicationSerializer diff --git a/apps/applications/filters.py b/apps/applications/filters.py deleted file mode 100644 index 948fa9187..000000000 --- a/apps/applications/filters.py +++ /dev/null @@ -1,12 +0,0 @@ -from django_filters import rest_framework as filters - -from .models import Application -from applications import const - - -class ApplicationFilter(filters.FilterSet): - type = filters.MultipleChoiceFilter(choices=const.ApplicationTypeChoices.choices) - - class Meta: - model = Application - fields = ['id', 'name', 'category', 'type', 'comment'] diff --git a/apps/perms/api/application/application_permission.py b/apps/perms/api/application/application_permission.py index 700b5384d..ce99120a2 100644 --- a/apps/perms/api/application/application_permission.py +++ b/apps/perms/api/application/application_permission.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # from applications.models import Application -from applications.filters import ApplicationFilter from perms.models import ApplicationPermission from perms import serializers from ..base import BasePermissionViewSet @@ -13,7 +12,11 @@ class ApplicationPermissionViewSet(BasePermissionViewSet): """ model = ApplicationPermission serializer_class = serializers.ApplicationPermissionSerializer - filterset_class = ApplicationFilter + filterset_fields = { + 'name': ['exact'], + 'category': ['exact'], + 'type': ['exact', 'in'], + } search_fields = ['name', 'category', 'type'] custom_filter_fields = BasePermissionViewSet.custom_filter_fields + [ 'application_id', 'application' diff --git a/apps/perms/api/application/user_permission/user_permission_applications.py b/apps/perms/api/application/user_permission/user_permission_applications.py index 5e5c27d22..17e5557e1 100644 --- a/apps/perms/api/application/user_permission/user_permission_applications.py +++ b/apps/perms/api/application/user_permission/user_permission_applications.py @@ -3,7 +3,6 @@ from rest_framework.generics import ListAPIView from rest_framework.response import Response -from applications.filters import ApplicationFilter from common.mixins.api import CommonApiMixin from applications.api.mixin import ( SerializeApplicationToTreeNodeMixin @@ -26,7 +25,13 @@ __all__ = [ class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView): only_fields = serializers.ApplicationGrantedSerializer.Meta.only_fields serializer_class = serializers.ApplicationGrantedSerializer - filterset_class = ApplicationFilter + filterset_fields = { + 'id': ['exact'], + 'name': ['exact'], + 'category': ['exact'], + 'type': ['exact', 'in'], + 'comment': ['exact'], + } search_fields = ['name', 'comment'] user: None