Example #1
0
File: views.py Project: voilet/cmdb
def idc_add(request):
    """ 添加IDC """
    if request.method == 'POST':
        init = request.GET.get("init", False)

        uf = IdcForm(request.POST)
        if uf.is_valid():
            idc_name = uf.cleaned_data['name']
            if IDC.objects.filter(name=idc_name):
                emg = u'添加失败, 此IDC %s 已存在!' % idc_name
                return my_render('assets/idc_add.html', locals(), request)
            uf.save()
            if zabbix_on:
                ret = zabbix_group_add(idc_name)
                if ret != 1:
                    emg = u'添加zabbix主机组 %s 失败!' % idc_name
                    return my_render('assets/idc_add.html', locals(), request)
            if not init:
                return HttpResponseRedirect("/assets/idc_list/")
            else:
                return HttpResponseRedirect('/assets/server/type/add/?init=true')

    else:
        uf = IdcForm()
    return render_to_response('assets/idc_add.html', locals(), context_instance=RequestContext(request))
Example #2
0
def idc_add(request):
    """ 添加IDC """
    if request.method == 'POST':
        init = request.GET.get("init", False)

        uf = IdcForm(request.POST)
        if uf.is_valid():
            idc_name = uf.cleaned_data['name']
            if IDC.objects.filter(name=idc_name):
                emg = u'添加失败, 此IDC %s 已存在!' % idc_name
                return my_render('assets/idc_add.html', locals(), request)
            uf.save()
            if zabbix_on:
                ret = zabbix_group_add(idc_name)
                if ret != 1:
                    emg = u'添加zabbix主机组 %s 失败!' % idc_name
                    return my_render('assets/idc_add.html', locals(), request)
            if not init:
                return HttpResponseRedirect("/assets/idc_list/")
            else:
                return HttpResponseRedirect(
                    '/assets/server/type/add/?init=true')

    else:
        uf = IdcForm()
    return render_to_response('assets/idc_add.html',
                              locals(),
                              context_instance=RequestContext(request))
Example #3
0
def idc_edit(request):
    uuid = request.GET.get('uuid', '')
    idc = get_object_or_404(IDC, uuid=uuid)
    if request.method == 'POST':
        uf = IdcForm(request.POST, instance=idc)
        if uf.is_valid():
            uf.save()
            return HttpResponseRedirect("/assets/idc_list/")
    else:
        uf = IdcForm(instance=idc)
        return my_render('assets/idc_edit.html', locals(), request)
Example #4
0
File: views.py Project: voilet/cmdb
def idc_edit(request):
    uuid = request.GET.get('uuid', '')
    idc = get_object_or_404(IDC, uuid=uuid)
    if request.method == 'POST':
        uf = IdcForm(request.POST, instance=idc)
        if uf.is_valid():
            uf.save()
            return HttpResponseRedirect("/assets/idc_list/")
    else:
        uf = IdcForm(instance=idc)
        return my_render('assets/idc_edit.html', locals(), request)
Example #5
0
def idc_add(request):
    temp_name = "cmdb/cmdb-header.html"

    if request.method == 'POST':
        form = IdcForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('idc_list')
    else:
        form = IdcForm
    return render(request, 'cmdb/idc_add.html', locals())
Example #6
0
def idc_edit(request, id):
    temp_name = "cmdb/cmdb-header.html"
    idc = Idc.objects.get(id=id)

    if request.method == 'POST':
        form = IdcForm(request.POST, instance=idc)
        if form.is_valid():
            form.save()
            return redirect('idc_list')
    else:
        form = IdcForm(instance=idc)

    return render(request, 'cmdb/idc_edit.html', locals())
Example #7
0
def idc_add(request):
    temp_name = "cmdb/cmdb-header.html"
    if request.method == "POST":
        idc_form = IdcForm(request.POST)
        if idc_form.is_valid():
            idc_form.save()
            tips = u"增加成功!"
            display_control = ""
        else:
            tips = u"增加失败!"
            display_control = ""
        return render(request, "cmdb/idc_add.html", locals())
    else:
        display_control = "none"
        idc_form = IdcForm()
        return render(request, "cmdb/idc_add.html", locals())
Example #8
0
def idc_add(request):
    """ 添加IDC """
    if request.method == 'POST':
        init = request.GET.get("init", False)
        uf = IdcForm(request.POST)
        if uf.is_valid():
            idc_name = uf.cleaned_data['name']
            if IDC.objects.filter(name=idc_name):
                emg = u'添加失败, 此IDC %s 已存在!' % idc_name
                return my_render('assets/idc_add.html', locals(), request)
            uf.save()
            if not init:
                return HttpResponseRedirect("/assets/idc_list/")
            # else:
            #	return HttpResponseRedirect('/assets/server/type/add/?init=true')
    else:
        uf = IdcForm()
    return render(request, 'assets/idc_add.html', locals())
Example #9
0
def editIDC(request, pk):
    idc = IDC.objects.get(id=pk)
    if request.method == 'POST':
        form = IdcForm(request.POST, instance=idc)
        front_idc = idc.name
        if form.is_valid():
            name = form.cleaned_data['name']
            if front_idc != name:
                if IDC.objects.filter(name=name).exists():
                    messages.add_message(request, messages.ERROR,
                                         u'{0} 已经存在'.format(name))
                    return redirect(reverse('idc'))
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 u'{0} 修改成功'.format(name))
            return redirect(reverse('idc'))
    form = IdcForm(instance=idc)
    return render(request, 'asset/edit_idc.html', locals())
Example #10
0
def idc_edit(request, idc_id):
    project = Idc.objects.get(id=idc_id)
    temp_name = "cmdb/cmdb-header.html"
    if request.method == 'POST':
        form = IdcForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('idc'))
    else:
        form = IdcForm(instance=project)
    display_control = "none"
    results = {
        'idc_form': form,
        'idc_id': idc_id,
        'request': request,
        'temp_name': temp_name,
        'display_control': display_control,
    }
    return render(request, 'cmdb/idc_base.html', results)
Example #11
0
def addIDC(request):
    if request.method == 'POST':
        form = IdcForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            if IDC.objects.filter(name=name).exists():
                messages.add_message(request, messages.ERROR,
                                     u'{0} 已经存在'.format(name))
                return redirect(reverse('add_idc'))
            new_idc = form.save()
            messages.add_message(request, messages.SUCCESS,
                                 u'{0} 添加成功'.format(name))
            return redirect(reverse('idc'))
    else:
        form = IdcForm()
    return render(request, 'asset/add_idc.html', locals())