def virtual_platform_edit(request): """ virtual_platform edit view """ header_title, path1, path2 = u'编辑平台', u'资产管理', u'编辑平台' platform_id = request.GET.get('id', '') platform = get_object(Virtual_platform, id=platform_id) host = get_object(Host_info,id=platform.host_info.id) idrac = get_object(Idrac,id=host.Idrac.id) if request.method == 'POST': platform_form = VirtualForm(request.POST,instance=platform) host_form = HostForm(request.POST, instance=host) idrac_form = IdracForm(request.POST,instance=idrac) # print host_form # print idrac_form if all((platform_form.is_valid(),host_form.is_valid(),idrac_form.is_valid())): platform_model = platform_form.save(commit=False) host_model = host_form.save(commit=False) host_model.Idrac = idrac_form.save() host_model.env_type = "virtual" host_model.save() platform_model.host_info = host_model platform_model.save() return HttpResponseRedirect(reverse('virtual_platform_list')) else: emg = "error" return my_render('jasset/virtual_platform_edit.html', locals(), request) else: platform_form = VirtualForm(instance=platform) host_form = HostForm(instance=host) idrac_form = IdracForm(instance=idrac) print host_form,idrac_form return my_render('jasset/virtual_platform_edit.html', locals(), request)
def virtual_platform_add(request): """ virtual_platform add view """ header_title, path1, path2 = u'添加虚拟化平台', u'资产管理', u'添加虚拟化平台' if request.method == 'POST': platform_form = VirtualForm(request.POST) host_form = AssetForm(request.POST) idrac_form = IdracForm(request.POST) # print platform_form # print host_form # print idrac_form if all((platform_form.is_valid(), host_form.is_valid()) ): # # if platform_form.is_valid(): platform_name = platform_form.cleaned_data['platform_name'] if Virtual_platform.objects.filter(platform_name=platform_name): emg = u'添加虚拟化平台失败, 此 %s 已存在!' % platform_name return my_render('jasset/virtual_platform_add.html', locals(), request) else: platform_model =platform_form.save(commit=False) host_model = host_form.save(commit=False) if idrac_form.is_valid(): host_model.remote_ip = idrac_form.save() host_model.env = 4 host_model.save() platform_model.host_info = host_model platform_model.save() smg = u'虚拟化平台: %s添加成功' % platform_name return HttpResponseRedirect(reverse('virtual_platform_list')) else: platform_form = VirtualForm() host_form = AssetForm() idrac_form = IdracForm() return my_render('jasset/virtual_platform_add.html', locals(), request)