combine all the result templates into one response_result.htm

standardize on the dictionary returned back from helpers, and to the template
This commit is contained in:
Jeffrey Forman 2012-10-28 20:32:37 -04:00
parent eb717e001a
commit 9f2bbdee0f
6 changed files with 54 additions and 85 deletions

View File

@ -75,8 +75,7 @@ def add_record(form_data):
keyring = None
response = []
response.append({ "type" : "Forward Record: %s.%s" % (str(form_data["record_name"]),
str(form_data["zone_name"])),
response.append({ "description" : "Forward Record Added: %(record_name)s.%(zone_name)s" % form_data,
"output" : add_forward_record(str(form_data["dns_server"]),
str(form_data["zone_name"]),
str(form_data["record_name"]),
@ -86,7 +85,7 @@ def add_record(form_data):
keyring)})
if form_data["create_reverse"]:
response.append({ "type" : "Reverse Record: %s" % form_data["record_data"],
response.append({ "description" : "Reverse Record Added: %(record_data)s" % form_data,
"output" : add_reverse_record(str(form_data["dns_server"]),
str(form_data["zone_name"]),
str(form_data["record_name"]),
@ -108,7 +107,9 @@ def add_cname_record(dns_server, zone_name, originating_record, cname, ttl, key_
update.replace(cname, int(ttl), 'CNAME', originating_record + ".")
response = dns.query.tcp(update, dns_server)
return response
return [{ "description" : "CNAME %s.%s points to %s" % (cname, zone_name, originating_record),
"output" : response}]
def delete_record(form_data, rr_items):
"""Delete a list of DNS records passed as strings in rr_items."""
@ -127,6 +128,6 @@ def delete_record(form_data, rr_items):
dns_update = dns.update.Update(domain, keyring = keyring)
dns_update.delete(record)
output = dns.query.tcp(dns_update, dns_server)
delete_response.append({ "rr_item" : current_rr_item, "output" : output })
delete_response.append({ "description" : "Delete record %s" % current_rr_item, "output" : output })
return delete_response

View File

@ -1,7 +1,7 @@
{% extends "base.htm" %}
{% block pageheader %}
Add cname record for {{record_name}}.{{zone_name}}
Add CNAME record for {{ originating_record }}
{% endblock pageheader %}
{% block body %}
@ -18,8 +18,8 @@ Add cname record for {{record_name}}.{{zone_name}}
<div class="control-group">
<label class="control-label">Originating Record: </label>
<div class="controls">
<span class="input-xlarge uneditable-input">{{record_name}}.{{zone_name}}</span>
<input type="hidden" name="originating_record" value="{{record_name}}.{{zone_name}}"/>
<span class="input-xlarge uneditable-input">{{originating_record}}</span>
<input type="hidden" name="originating_record" value="{{originating_record}}"/>
</div>
</div>
@ -27,9 +27,14 @@ Add cname record for {{record_name}}.{{zone_name}}
<label class="control-label">CNAME: </label>
<div class="controls">
<div class="input-append">
<input class="span2" size="100" name="cname" type="text"><span class="add-on">.{{zone_name}}</span>
<input type="hidden" name="zone_name" value="{{zone_name}}"/>
<input class="span2" size="100" name="cname" type="text"><span class="add-on">.{{zone_name}}</span>
<input type="hidden" name="zone_name" value="{{zone_name}}"/>
</div>
{% if form_errors.cname %}
<div class="alert alert-error">
CNAME: {{ form_errors.cname|stringformat:"s"|striptags }} Previous Value: {{ form_data.cname }}
</div>
{% endif %}
</div>
</div>

View File

@ -1,20 +0,0 @@
{% extends "base.htm" %}
{% block pageheader %}
Add CNAME Record Result
{% endblock pageheader %}
{% block body %}
<table class="table">
<tr>
<th>CNAME</th>
<th>Add CNAME Result</th>
</tr>
<tr>
<td>{{ rr_data.cname }}.{{rr_data.zone_name }} points to {{ rr_data.originating_record }}</td>
<td><pre>{{ response }}</pre></td>
</tr>
</table>
{% endblock body %}

View File

@ -1,23 +0,0 @@
{% extends "base.htm" %}
{% block pageheader %}
Delete Record(s) Result
{% endblock pageheader %}
{% block body %}
<table class="table">
{% for current_response in delete_result %}
<tr>
<th>Record</th>
<th>Delete Result</th>
</tr>
<tr>
<td>{{ current_response.rr_item }}</td>
<td><pre>{{ current_response.output }}</pre></td>
</tr>
{% endfor %}
</table>
{% endblock body %}

View File

@ -2,18 +2,18 @@
{% block pageheader %}
Add Record Result
Record Result
{% endblock pageheader %}
{% block body %}
<table class="table">
{% for current_response in response %}
<tr>
<th>Record:</th>
<th>Record</th>
<th>Output</th>
</tr>
<tr>
<td>{{ current_response.type }}</td>
<td>{{ current_response.description }}</td>
<td><pre>{{ current_response.output }}</pre></td>
</tr>
{% endfor %}

View File

@ -6,6 +6,9 @@ import re
RE_UNICODEARRAY = re.compile(r"u'(.*?)'")
class BinderException(Exception):
pass
def home_index(request):
return render(request, 'index.htm')
@ -52,11 +55,11 @@ def view_add_record(request, dns_server, zone_name):
""" View to provide form to add a DNS record. """
return render(request, 'bcommon/add_record_form.htm',
{ "dns_server" : dns_server,
"zone_name" : zone_name })
"zone_name" : zone_name,
"tsig_keys" : models.Key.objects.all() })
def view_add_record_result(request):
""" Process the input given to add a DNS record. """
errors = None
if request.method == "GET":
return redirect('/')
@ -65,10 +68,10 @@ def view_add_record_result(request):
cd = form.cleaned_data
try:
add_record_response = helpers.add_record(cd)
except BinderException, errors:
except BinderException, error:
pass
return render(request, 'bcommon/add_record_result.htm',
{ "errors" : errors,
return render(request, 'bcommon/response_result.htm',
{ "errors" : error,
"response" : add_record_response })
return render(request, 'bcommon/add_record_form.htm',
@ -81,38 +84,41 @@ def view_add_cname_record(request, dns_server, zone_name, record_name):
""" Process given input to add a CNAME pointer."""
return render(request, "bcommon/add_cname_record_form.htm",
{ "dns_server" : dns_server,
"originating_record" : "%s.%s" % (record_name, zone_name),
"zone_name" : zone_name,
"record_name" : record_name,
"tsig_keys" : models.Key.objects.all() })
def view_add_cname_result(request):
if request.method == "GET":
# Return home. You shouldn't trying to directly access
# the url for deleting records.
return redirect('/')
form = forms.FormAddCnameRecord(request.POST)
if form.is_valid():
cd = form.cleaned_data
else:
return "bad form" # TODO: Send back the form pre-populated with the error
try:
add_cname_response = helpers.add_cname_record(
str(cd["dns_server"]),
str(cd["zone_name"]),
str(cd["originating_record"]),
str(cd["cname"]),
str(cd["ttl"]),
str(cd["key_name"]))
except BinderException, error:
pass
try:
add_cname_response = helpers.add_cname_record(
str(cd["dns_server"]),
str(cd["zone_name"]),
str(cd["originating_record"]),
str(cd["cname"]),
str(cd["ttl"]),
str(cd["key_name"]))
except Exception, err:
return render(request, 'bcommon/add_cname_result.htm',
{ 'errors' : err,
'rr_data' : cd })
return render(request, 'bcommon/response_result.htm',
{ 'errors' : error,
'response' : add_cname_response })
return render(request, "bcommon/add_cname_record_form.htm",
{ "dns_server" : request.POST["dns_server"],
"zone_name" : request.POST["zone_name"],
"record_name" : request.POST["cname"],
"originating_record" : request.POST["originating_record"],
"form_data" : request.POST,
"form_errors" : form.errors,
"tsig_keys" : models.Key.objects.all() })
return render(request, 'bcommon/add_cname_result.htm',
{ 'response' : add_cname_response,
'rr_data' : cd })
def view_delete_record(request):
if request.method == "GET":
@ -145,8 +151,8 @@ def view_delete_result(request):
try:
delete_result = helpers.delete_record(request.POST, rr_items)
except Exception, err:
return render(request, 'bcommon/delete_record_result.htm',
{ "errors" : err }),
return render(request, 'bcommon/response_result.htm.htm',
{ "errors" : err })
return render(request, 'bcommon/delete_record_result.htm',
{ 'delete_result' : delete_result })
return render(request, 'bcommon/response_result.htm',
{ 'response' : delete_result })