methods.py 文件源码

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

项目:mist.api 作者: mistio 项目源码 文件源码
def update_whitelist_ips(auth_context, ips):
    """
    This function takes a list of dicts in the form:
    [{cidr:'cidr1', 'description:'desc1'},
    {cidr:'cidr2', 'description:'desc2'}]
    and saves them in the User.ips field.
    """

    user = auth_context.user

    user.ips = []
    for ip_dict in ips:
        wip = WhitelistIP()
        wip.cidr = ip_dict['cidr']
        wip.description = ip_dict['description']
        user.ips.append(wip)

    try:
        user.save()
    except ValidationError as e:
        raise BadRequestError({"msg": e.message, "errors": e.to_dict()})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号