Python flask_restful 模块,marshal_with() 实例源码

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

项目:OctoPrint-Dashboard    作者:meadowfrey    | 项目源码 | 文件源码
def selective_marshal_with(fields, fields_private):
    """
    Selective response marshalling.
    Adds specified fields to response if user has superadmin permission
    """

    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            model = fields
            if g.user.superadmin:
                model.update(fields_private)
            func2 = marshal_with(model)(func)
            return func2(*args, **kwargs)

        return wrapper

    return decorator