From 5523e79ded0693a4a36584c5315a033612719b6a Mon Sep 17 00:00:00 2001 From: Jeffrey Forman Date: Sun, 24 Apr 2011 21:10:25 -0400 Subject: [PATCH] Preliminary error handling around key errors when adding a record --- binder/bcommon/helpers.py | 6 +++++- binder/bcommon/views.py | 6 ++++++ binder/templates/bcommon/add_record_result.htm | 11 +++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/binder/bcommon/helpers.py b/binder/bcommon/helpers.py index b5f1e32..c8d8dbb 100644 --- a/binder/bcommon/helpers.py +++ b/binder/bcommon/helpers.py @@ -62,5 +62,9 @@ def add_record(clean_data): keyring = dns.tsigkeyring.from_text({ key_name : key_data }) dns_update = dns.update.Update(clean_data['rr_domain'], keyring = keyring, keyalgorithm=key_algorithm) dns_update.replace(str(clean_data['rr_name']), 10, str(clean_data['rr_type']), str(clean_data['rr_data'])) - response = dns.query.tcp(dns_update, clean_data['dns_hostname']) + try: + response = dns.query.tcp(dns_update, clean_data['dns_hostname']) + except dns.tsig.PeerBadKey: + return {'errors' : "There was a problem adding your record due to a TSIG key issue. Please resolve that first." } + return response diff --git a/binder/bcommon/views.py b/binder/bcommon/views.py index 829d316..19d6788 100644 --- a/binder/bcommon/views.py +++ b/binder/bcommon/views.py @@ -74,6 +74,12 @@ def add_record_result(request): if form.is_valid(): cd = form.cleaned_data response = add_record(cd) + + if 'errors' in response: + return render_to_response('bcommon/add_record_result.htm', + { 'errors' : response['errors'] }, + context_instance=RequestContext(request)) + else: return render_to_response('bcommon/add_record_result.htm', { 'response' : response }, context_instance=RequestContext(request)) diff --git a/binder/templates/bcommon/add_record_result.htm b/binder/templates/bcommon/add_record_result.htm index 27c4439..94c729e 100644 --- a/binder/templates/bcommon/add_record_result.htm +++ b/binder/templates/bcommon/add_record_result.htm @@ -2,11 +2,14 @@ {% block pageheader %} -Result: + {% endblock pageheader %} {% block body %} -
-  {{ response }}
-
+{% if not errors %} + Result: +
+    {{ response }}
+  
+{% endif %} {% endblock body %}