forms.py 文件源码

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

项目:docker-box 作者: MicroPyramid 项目源码 文件源码
def clean(self):
        ram = self.cleaned_data.get('ram', None)
        cores = self.cleaned_data.get('cores', None)

        if cores:
            cores = random_sample(range(0, cpu_count()), cores)
            cores = ','.join(map(str, cores))
            self.cleaned_data['cores'] = cores
        else:
            cores = cpu_count()
            cores = str(list(range(0, cores))).strip('[]').replace(" ", "")
            self.cleaned_data['cores'] = cores

        if ram:
            ram = int(ram)
            self.cleaned_data['ram'] = ram
        else:
            ram = int(DHost.memory('total'))
            self.cleaned_data['ram'] = ram

        if self.ssh_users:
            for ssh_user in self.ssh_users:
                user_obj = User.objects.get(email=ssh_user)
                if not user_obj.ssh_pub_key:
                    raise forms.ValidationError("SSH key not found")
        return self.cleaned_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号