示例#1
0
文件: views.py 项目: qsm365/cmdb
def edit_group(request,groupid=0):
    re=group.show(groupid)
    if re:
        context={}
        context['title']="Group Edit"
        context['group']=re
        context['members']=group.getMember(groupid)
        if context['group'].type=="Host":
            for p in context['members']:
                p.setIP(host.getIP(p.id))
        return render(request, 'core/edit_group.html',context)
    else:
        return HttpResponseRedirect("/cmdb/group")
示例#2
0
def edit_group(request, groupid=0):
    re = group.show(groupid)
    if re:
        context = {}
        context['title'] = "Group Edit"
        context['group'] = re
        context['members'] = group.getMember(groupid)
        if context['group'].type == "Host":
            for p in context['members']:
                p.setIP(host.getIP(p.id))
        return render(request, 'core/edit_group.html', context)
    else:
        return HttpResponseRedirect("/cmdb/group")
示例#3
0
文件: views.py 项目: qsm365/cmdb
def groups(request,groupid=0,grouptype=""):
    if (not groupid):
        if request.method=='POST':
            meth=request.POST.get('_method','show')
            if meth=='new':
                name=request.POST.get('name')
                t=request.POST.get('type')
                member=request.POST.get('member')
                if name and t and member:
                    m=member.split(';')
                    m.pop(-1)
                    group.addMember(group.create(name, t), m)
                return HttpResponse("ok")
        else:
            context={}
            q=request.GET.get('q')
            p=int(request.GET.get('page',1))
            if q:
                re=group.search(q)
                context['title']="Groups in search"
            elif grouptype:
                re=group.listByType(grouptype)
                context['title']=grouptype.capitalize()+" Groups Manage"
            else:
                re=group.showAll()
                context['title']="Group List"
            if re:
                page=Paginator(re,10)
                if p>0 and p<=page.num_pages:
                    context['page']=page.page(p)
                else:
                    context['page']=page.page(1)
                context['num_pages']=page.num_pages
                for p in context['page']:
                    p.setUrl("/cmdb/group/"+str(p.id))
            context['uri']='group'
            context['with_group']=False
            context['with_new']=True
            return render(request,'list.html',context)
    else:
        if request.method=="POST":
            meth=request.POST.get('_method','show')
            if meth=='delete':
                group.delete(groupid)
                return HttpResponse("ok")
            if meth=='edit':
                name=request.POST.get('name')
                add_list=request.POST.get('add')
                if add_list:
                    group.addMember(groupid, add_list.split(','))
                del_list=request.POST.get('del')
                if del_list:
                    group.delMember(groupid, del_list.split(','))
                group.changeName(groupid, name)
                return HttpResponse("ok")
        else:
            re=group.show(groupid)
            if re:
                context={}
                context['group']=group.show(groupid)
                context['members']=group.getMember(groupid)
                context['title']="Group Info"
                if context['group'].type=="Host":
                    for p in context['members']:
                        p.setIP(host.getIP(p.id))
                return render(request,'core/group.html',context)
            else:
                return HttpResponseRedirect("/cmdb/group")
示例#4
0
def groups(request, groupid=0, grouptype=""):
    if (not groupid):
        if request.method == 'POST':
            meth = request.POST.get('_method', 'show')
            if meth == 'new':
                name = request.POST.get('name')
                t = request.POST.get('type')
                member = request.POST.get('member')
                if name and t and member:
                    m = member.split(';')
                    m.pop(-1)
                    group.addMember(group.create(name, t), m)
                return HttpResponse("ok")
        else:
            context = {}
            q = request.GET.get('q')
            p = int(request.GET.get('page', 1))
            if q:
                re = group.search(q)
                context['title'] = "Groups in search"
            elif grouptype:
                re = group.listByType(grouptype)
                context['title'] = grouptype.capitalize() + " Groups Manage"
            else:
                re = group.showAll()
                context['title'] = "Group List"
            if re:
                page = Paginator(re, 10)
                if p > 0 and p <= page.num_pages:
                    context['page'] = page.page(p)
                else:
                    context['page'] = page.page(1)
                context['num_pages'] = page.num_pages
                for p in context['page']:
                    p.setUrl("/cmdb/group/" + str(p.id))
            context['uri'] = 'group'
            context['with_group'] = False
            context['with_new'] = True
            return render(request, 'list.html', context)
    else:
        if request.method == "POST":
            meth = request.POST.get('_method', 'show')
            if meth == 'delete':
                group.delete(groupid)
                return HttpResponse("ok")
            if meth == 'edit':
                name = request.POST.get('name')
                add_list = request.POST.get('add')
                if add_list:
                    group.addMember(groupid, add_list.split(','))
                del_list = request.POST.get('del')
                if del_list:
                    group.delMember(groupid, del_list.split(','))
                group.changeName(groupid, name)
                return HttpResponse("ok")
        else:
            re = group.show(groupid)
            if re:
                context = {}
                context['group'] = group.show(groupid)
                context['members'] = group.getMember(groupid)
                context['title'] = "Group Info"
                if context['group'].type == "Host":
                    for p in context['members']:
                        p.setIP(host.getIP(p.id))
                return render(request, 'core/group.html', context)
            else:
                return HttpResponseRedirect("/cmdb/group")