def hosts(request,hostid=0,groupid=0): if not hostid: context={} q=request.GET.get('q') p=int(request.GET.get('page',1)) if q: re=host.search(q) context['title']="Hosts in search" elif groupid: re=host.listByGroup(groupid) context['title']="Hosts in Group" else: re=host.showAll() context['title']="Host 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.setIP(host.getIP(p.id)) p.setUrl("/cmdb/host/"+str(p.id)) context['grouplist']=group.listByType('Host') context['uri']='host' context['with_group']=True context['with_new']=False return render(request, 'list.html',context) else: if request.method=='POST': meth=request.POST.get('_method','show') if meth=='delete': host.delete(hostid) return HttpResponse("ok") elif meth=='edit_desc': desc=unquote(request.POST.get('desc','')) host.edit_desc(hostid,desc) return HttpResponse("ok") elif meth=='addparam': key=request.POST.get('key') value=request.POST.get('value') return HttpResponse(parameter.createByHost(hostid,key,value)) elif meth=='delparam': pid=request.POST.get('pid') parameter.delete(pid) return HttpResponse("ok") else: re=host.show(hostid) if re: context=re context['title']="Host Info" return render(request, 'core/host.html',context) else: return HttpResponseRedirect("/cmdb/host")
def hosts(request, hostid=0, groupid=0): if not hostid: context = {} q = request.GET.get('q') p = int(request.GET.get('page', 1)) if q: re = host.search(q) context['title'] = "Hosts in search" elif groupid: re = host.listByGroup(groupid) context['title'] = "Hosts in Group" else: re = host.showAll() context['title'] = "Host 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.setIP(host.getIP(p.id)) p.setUrl("/cmdb/host/" + str(p.id)) context['grouplist'] = group.listByType('Host') context['uri'] = 'host' context['with_group'] = True context['with_new'] = False return render(request, 'list.html', context) else: if request.method == 'POST': meth = request.POST.get('_method', 'show') if meth == 'delete': host.delete(hostid) return HttpResponse("ok") elif meth == 'edit_desc': desc = unquote(request.POST.get('desc', '')) host.edit_desc(hostid, desc) return HttpResponse("ok") elif meth == 'addparam': key = request.POST.get('key') value = request.POST.get('value') return HttpResponse(parameter.createByHost(hostid, key, value)) elif meth == 'delparam': pid = request.POST.get('pid') parameter.delete(pid) return HttpResponse("ok") else: re = host.show(hostid) if re: context = re context['title'] = "Host Info" return render(request, 'core/host.html', context) else: return HttpResponseRedirect("/cmdb/host")
def host_find_json(request): if request.method == 'GET': if len(request.GET['q'])>=3: re=host.search(request.GET['q']) if re: respones=[] for i in re: s={} s['id']=i.id s['name']=i.name s['ip']=host.getIP(i.id) respones.append(s) return JsonResponse(respones,safe=False) return JsonResponse([],safe=False)
def host_find_json(request): if request.method == 'GET': if len(request.GET['q']) >= 3: re = host.search(request.GET['q']) if re: respones = [] for i in re: s = {} s['id'] = i.id s['name'] = i.name s['ip'] = host.getIP(i.id) respones.append(s) return JsonResponse(respones, safe=False) return JsonResponse([], safe=False)