Python rest_framework.filters 模块,BaseFilterBackend() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用rest_framework.filters.BaseFilterBackend()

项目:gee-bridge    作者:francbartoli    | 项目源码 | 文件源码
def additional_schema(schema):
    """
    rest framework does not provide a way to override the schema on
    a per endpoint basis.  this is a cheap way to get the fields to
    appear on the swagger web interface through the filter_backends

    Args:
        schema (TYPE): Description
    """
    class SwaggerFilterBackend(object):
        """Summary
        """
        def get_schema_fields(self, view):
            """Summary

            Args:
                view (TYPE): Description

            Returns:
                TYPE: Description
            """
            keys = ('name', 'required', 'location', 'type', 'description')
            return [
                coreapi.Field(**{
                    key: val for key, val in field.items() if key in keys})
                for field in schema.values()
            ]

        def filter_queryset(self, request, queryset, view):
            """Summary

            Args:
                request (TYPE): Description
                queryset (TYPE): Description
                view (TYPE): Description

            Returns:
                TYPE: Description
            """
            # do nothing
            return queryset

    def wrapper(cls):
        """Summary

        Returns:
            TYPE: Description
        """
        cls.filter_backends = (BaseFilterBackend, )
        cls.filter_backends = list(cls.filter_backends) + [SwaggerFilterBackend]
        return cls

    return wrapper