diff options
author | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-09-13 19:13:08 +0000 |
---|---|---|
committer | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-09-13 19:13:08 +0000 |
commit | 5d4849dc21d7aae7e861033ab5aa3bdeb17847c1 (patch) | |
tree | 4b4ae31b1e39caf36a8fce2ae7c21dad6ff41822 /src/lib/Server/Hostbase/hostbase/views.py | |
parent | 38df760dd986caa7e786f0f9efb6bc16bd107c15 (diff) | |
download | bcfg2-5d4849dc21d7aae7e861033ab5aa3bdeb17847c1.tar.gz bcfg2-5d4849dc21d7aae7e861033ab5aa3bdeb17847c1.tar.bz2 bcfg2-5d4849dc21d7aae7e861033ab5aa3bdeb17847c1.zip |
more web layout changes
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2248 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Hostbase/hostbase/views.py')
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/views.py | 109 |
1 files changed, 58 insertions, 51 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index d2321e364..48e924ddc 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -103,18 +103,61 @@ def look(request, host_id): host = Host.objects.get(id=host_id) interfaces = [] for interface in host.interface_set.all(): - interfaces.append((interface, interface.ip_set.all())) - comments = [line for line in host.comments.split("\n")] + interfaces.append([interface, interface.ip_set.all()]) return render_to_response('%s/host.html' % templatedir, {'host': host, - 'interfaces': interfaces, - 'comments': comments}) + 'interfaces': interfaces}) def dns(request, host_id): - temp = Template(open('%s/dns.html' % templatedir).read()) - hostdata = gethostdata(host_id, True) - temp = fill(temp, hostdata, True) - return HttpResponse(str(temp)) + host = Host.objects.get(id=host_id) + ips = [] + info = [] + cnames = [] + mxs = [] + for interface in host.interface_set.all(): + ips.extend(interface.ip_set.all()) + for ip in ips: + info.append([ip, ip.name_set.all()]) + for name in ip.name_set.all(): + cnames.extend(name.cname_set.all()) + mxs.append((name.id, name.mxs.all())) + return render_to_response('%s/dns.html' % templatedir, + {'host': host, + 'info': info, + 'cnames': cnames, + 'mxs': mxs}) + +def gethostdata(host_id, dnsdata=False): + """Grabs the necessary data about a host + Replaces a lot of repeated code""" + hostdata = {} + hostdata['ips'] = {} + hostdata['names'] = {} + hostdata['cnames'] = {} + hostdata['mxs'] = {} + hostdata['host'] = Host.objects.get(id=host_id) + hostdata['interfaces'] = hostdata['host'].interface_set.all() + for interface in hostdata['interfaces']: + hostdata['ips'][interface.id] = interface.ip_set.all() + if dnsdata: + for ip in hostdata['ips'][interface.id]: + hostdata['names'][ip.id] = ip.name_set.all() + for name in hostdata['names'][ip.id]: + hostdata['cnames'][name.id] = name.cname_set.all() + hostdata['mxs'][name.id] = name.mxs.all() + return hostdata + +def fill(template, hostdata, dnsdata=False): + """Fills a generic template + Replaces a lot of repeated code""" + if dnsdata: + template.names = hostdata['names'] + template.cnames = hostdata['cnames'] + template.mxs = hostdata['mxs'] + template.host = hostdata['host'] + template.interfaces = hostdata['interfaces'] + template.ips = hostdata['ips'] + return template def edit(request, host_id): """Edit general host information @@ -385,39 +428,6 @@ def dnsedit(request, host_id): temp = fill(temp, hostdata, True) temp.request = request return HttpResponse(str(temp)) - -def gethostdata(host_id, dnsdata=False): - """Grabs the necessary data about a host - Replaces a lot of repeated code""" - hostdata = {} - hostdata['ips'] = {} - hostdata['names'] = {} - hostdata['cnames'] = {} - hostdata['mxs'] = {} - hostdata['host'] = Host.objects.get(id=host_id) - hostdata['interfaces'] = hostdata['host'].interface_set.all() - for interface in hostdata['interfaces']: - hostdata['ips'][interface.id] = interface.ip_set.all() - if dnsdata: - for ip in hostdata['ips'][interface.id]: - hostdata['names'][ip.id] = ip.name_set.all() - for name in hostdata['names'][ip.id]: - hostdata['cnames'][name.id] = name.cname_set.all() - hostdata['mxs'][name.id] = name.mxs.all() - return hostdata - -def fill(template, hostdata, dnsdata=False): - """Fills a generic template - Replaces a lot of repeated code""" - if dnsdata: - template.names = hostdata['names'] - template.cnames = hostdata['cnames'] - template.mxs = hostdata['mxs'] - template.host = hostdata['host'] - template.interfaces = hostdata['interfaces'] - template.ips = hostdata['ips'] - return template - def new(request): """Function for creating a new host in hostbase @@ -435,9 +445,8 @@ def new(request): host.status = 'active' host.save() else: - temp = Template(open('%s/errors.html' % templatedir).read()) - temp.failures = validate(request, True) - return HttpResponse(str(temp)) + return render_to_response('%s/errors.html' % templatedir, + {'failures': validate(request, True)}) if request.POST['mac_addr_new']: new_inter = Interface(host=host, mac_addr=request.POST['mac_addr_new'], @@ -558,13 +567,11 @@ def new(request): host.save() return HttpResponseRedirect('/hostbase/%s/' % host.id) else: - temp = Template(open('%s/new.html' % templatedir).read()) - temp.TYPE_CHOICES = Interface.TYPE_CHOICES - temp.NETGROUP_CHOICES = Host.NETGROUP_CHOICES - temp.CLASS_CHOICES = Host.CLASS_CHOICES - temp.SUPPORT_CHOICES = Host.SUPPORT_CHOICES - temp.failures = False - return HttpResponse(str(temp)) + return render_to_response('%s/new.html' % templatedir, + {'TYPE_CHOICES': Interface.TYPE_CHOICES, + 'NETGROUP_CHOICES': Host.NETGROUP_CHOICES, + 'CLASS_CHOICES': Host.CLASS_CHOICES, + 'SUPPORT_CHOICES': Host.SUPPORT_CHOICES}) def validate(request, new=False, host_id=None): """Function for checking form data""" |