Merge branch '404-for-not-existing-servers' of https://github.com/Dunedan/binder into Dunedan-404-for-not-existing-servers

This commit is contained in:
jeffrey forman 2015-04-03 22:13:42 -04:00
commit a099a43250
2 changed files with 13 additions and 18 deletions

View File

@ -34,10 +34,7 @@ class GetTests(TestCase):
""" Get a zone list for a server not in the database.""" """ Get a zone list for a server not in the database."""
server_name = "unconfigured.server.net" server_name = "unconfigured.server.net"
response = self.client.get(reverse("server_zone_list", args=(server_name, ))) response = self.client.get(reverse("server_zone_list", args=(server_name, )))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 404)
self.assertContains(response, ('<div class="alert alert-error">Errors were encountered: <br>'
'There is no configured server by that name: unconfigured.server.net </div>'),
html=True)
class PostTests(TestCase): class PostTests(TestCase):

View File

@ -1,7 +1,7 @@
### Binder VIews ### Binder VIews
# 3rd Party # 3rd Party
from django.shortcuts import redirect, render from django.shortcuts import get_object_or_404, redirect, render
# App Imports # App Imports
from binder import exceptions, forms, helpers, models from binder import exceptions, forms, helpers, models
@ -27,11 +27,9 @@ def view_server_zones(request, dns_server):
""" Display the list of DNS zones a particular DNS host provides. """ """ Display the list of DNS zones a particular DNS host provides. """
errors = "" errors = ""
zone_array = {} zone_array = {}
try:
this_server = models.BindServer.objects.get(hostname=dns_server) this_server = get_object_or_404(models.BindServer, hostname=dns_server)
except models.BindServer.DoesNotExist, err:
errors = "There is no configured server by that name: %s" % dns_server
else:
try: try:
zone_array = this_server.list_zones() zone_array = this_server.list_zones()
except exceptions.ZoneException, err: except exceptions.ZoneException, err:
@ -47,7 +45,9 @@ def view_zone_records(request, dns_server, zone_name):
""" Display the list of records for a particular zone. """ """ Display the list of records for a particular zone. """
errors = "" errors = ""
zone_array = {} zone_array = {}
this_server = models.BindServer.objects.get(hostname=dns_server)
this_server = get_object_or_404(models.BindServer, hostname=dns_server)
try: try:
zone_array = this_server.list_zone_records(zone_name) zone_array = this_server.list_zone_records(zone_name)
except exceptions.TransferException, err: except exceptions.TransferException, err:
@ -55,8 +55,6 @@ def view_zone_records(request, dns_server, zone_name):
{ "errors" : err, { "errors" : err,
"zone_name" : zone_name, "zone_name" : zone_name,
"dns_server" : this_server}) "dns_server" : this_server})
except models.BindServer.DoesNotExist:
errors = "Requesting a zone listing for a Bind server that is not configured: %s" % dns_server
return render(request, "bcommon/list_zone.html", return render(request, "bcommon/list_zone.html",
{ "zone_array" : zone_array, { "zone_array" : zone_array,
@ -67,7 +65,7 @@ def view_zone_records(request, dns_server, zone_name):
def view_add_record(request, dns_server, zone_name): def view_add_record(request, dns_server, zone_name):
""" View to provide form to add a DNS record. """ """ View to provide form to add a DNS record. """
this_server = models.BindServer.objects.get(hostname=dns_server) this_server = get_object_or_404(models.BindServer, hostname=dns_server)
return render(request, "bcommon/add_record_form.html", return render(request, "bcommon/add_record_form.html",
{ "dns_server" : this_server, { "dns_server" : this_server,
@ -128,7 +126,7 @@ def view_add_record_result(request):
def view_add_cname_record(request, dns_server, zone_name, record_name): def view_add_cname_record(request, dns_server, zone_name, record_name):
""" Process given input to add a CNAME pointer.""" """ Process given input to add a CNAME pointer."""
this_server = models.BindServer.objects.get(hostname=dns_server) this_server = get_object_or_404(models.BindServer, hostname=dns_server)
return render(request, "bcommon/add_cname_record_form.html", return render(request, "bcommon/add_cname_record_form.html",
{ "dns_server" : this_server, { "dns_server" : this_server,