iprange.py 文件源码

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

项目:maas 作者: maas 项目源码 文件源码
def __init__(
            self, data=None, instance=None, request=None, *args, **kwargs):
        if data is None:
            data = {}
        else:
            data = data.copy()
        # If this is a new IPRange, fill in the 'user' and 'subnet' fields
        # automatically, if necessary.
        if instance is None:
            start_ip = data.get('start_ip')
            subnet = data.get('subnet')
            if subnet is None and start_ip is not None:
                subnet = Subnet.objects.get_best_subnet_for_ip(start_ip)
                if subnet is not None:
                    data['subnet'] = subnet.id
            if request is not None:
                data['user'] = request.user.username
        elif instance.user and 'user' not in data:
            data['user'] = instance.user.username
        super().__init__(
            data=data, instance=instance, *args, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号