|
|
|
@ -13,17 +13,16 @@ from rest_framework.fields import DateTimeField
|
|
|
|
|
from rest_framework.serializers import ValidationError |
|
|
|
|
|
|
|
|
|
from common import const |
|
|
|
|
from common.db.fields import RelatedManager |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('jumpserver.common') |
|
|
|
|
|
|
|
|
|
__all__ = [ |
|
|
|
|
"DatetimeRangeFilter", "IDSpmFilter", |
|
|
|
|
'IDInFilter', "CustomFilter", |
|
|
|
|
"BaseFilterSet" |
|
|
|
|
"BaseFilterSet", 'IDNotFilter' |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
from common.db.fields import RelatedManager |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseFilterSet(drf_filters.FilterSet): |
|
|
|
|
def do_nothing(self, queryset, name, value): |
|
|
|
@ -149,6 +148,25 @@ class IDInFilter(filters.BaseFilterBackend):
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IDNotFilter(filters.BaseFilterBackend): |
|
|
|
|
def get_schema_fields(self, view): |
|
|
|
|
return [ |
|
|
|
|
coreapi.Field( |
|
|
|
|
name='id!', location='query', required=False, |
|
|
|
|
type='string', example='/api/v1/users/users?id!=1,2,3', |
|
|
|
|
description='Exclude by id set' |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
def filter_queryset(self, request, queryset, view): |
|
|
|
|
ids = request.query_params.get('id!') |
|
|
|
|
if not ids: |
|
|
|
|
return queryset |
|
|
|
|
id_list = [i.strip() for i in ids.split(',')] |
|
|
|
|
queryset = queryset.exclude(id__in=id_list) |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomFilter(filters.BaseFilterBackend): |
|
|
|
|
|
|
|
|
|
def get_schema_fields(self, view): |
|
|
|
|