Beispiel #1
0
def virtual_platform_detail(request):
    if request.method == "GET":
        conn = Q()
        q1 = Q()
        q1.connector = "OR"
        keyword = request.GET.get('keyword', '')
        if keyword:
            coditions_list = ["host_ip", "host_name", "host_comments"]
            for i in coditions_list:
                q1.children.append(("%s__icontains" % i, keyword))
            conn.add(q1, "AND")
        else:
            pass
        platform_id = request.GET.get('id',"")
        platform = get_object(Virtual_platform,id=platform_id)
        q2 = Q()
        q2.connector = "AND"
        q2.children.append(("server", platform))
        conn.add(q2, "AND")
        virtual_host_form = VirtualHostForm()
        header_title, path1, path2 = u'虚拟化平台详细内容', u'资产管理', u'%s详细内容'%platform.platform_name
        posts = Virtual_host.objects.select_related().filter(conn)
        contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
        return  my_render('jasset/virtual_platform_detail.html',locals(),request)
    else:
        # add new virtual host in platform
        platform_id = request.POST.get("id")
        virtual_host_form = VirtualHostForm(request.POST)
        virtual_host_model = virtual_host_form.save(commit=False)
        virtual_host_model.server = Virtual_platform.objects.get(id=platform_id)
        virtual_host_model.save()
        return HttpResponse("true")
Beispiel #2
0
def virtual_host_edit(request):
    """
    virtual_host  edit view
    """
    header_title, path1, path2 = u'修改虚拟主机', u'资产管理', u'修改虚拟主机'
    platform_id = request.GET.get("platform_id")
    virtual_host_id = request.GET.get('id', '')
    virtual_host = get_object(Virtual_host, id=virtual_host_id)
    if request.method == 'POST':
        virtual_host_form  = VirtualHostForm(request.POST, instance=virtual_host)

        if virtual_host_form.is_valid():
            virtual_host_form.save()
            return HttpResponseRedirect(reverse('virtual_platform_detail')+"?id="+platform_id)
        else:
            emg = "error"
            return my_render('jasset/virtual_host_edit.html', locals(), request)
    else:
        print platform_id
        virtual_host_form = VirtualHostForm(instance=virtual_host)
        print virtual_host_form
        return my_render('jasset/virtual_host_edit.html', locals(), request)