decorators.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:wagtail-flags 作者: cfpb 项目源码 文件源码
def flag_check(flag_name, state, fallback=None, **fc_kwargs):
    """ Check that a given flag has the given state.
    If the state does not match, perform the fallback. """
    def decorator(func):
        def inner(request, *args, **kwargs):
            enabled = flag_state(flag_name, request=request, **fc_kwargs)

            if ((state and enabled) or (not state and not enabled)):
                return func(request, *args, **kwargs)
            elif fallback is not None:
                return fallback(request, *args, **kwargs)
            else:
                raise Http404

        return wraps(func)(inner)

    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号