From eb717e001a1102a6a35a8db0988ec20919d7e851 Mon Sep 17 00:00:00 2001 From: Jeffrey Forman Date: Sun, 28 Oct 2012 14:49:15 -0400 Subject: [PATCH] Bring things up to 1.4 standards. A LOT of file moves, simplifying of paths. Removed bcommon directory under binder --- binder/{bcommon => }/admin.py | 2 +- binder/bcommon/__init__.py | 0 binder/bcommon/tests.py | 23 --- binder/bcommon/views.py | 170 ------------------ binder/{bcommon => }/forms.py | 2 +- binder/{bcommon => }/helpers.py | 6 +- binder/{bcommon => }/keyutils.py | 2 +- binder/manage.py | 11 -- binder/{bcommon => }/models.py | 0 binder/settings.py | 18 +- binder/{files => }/static/bootstrap | 0 .../css/bootstrap-responsive.css | 0 .../css/bootstrap-responsive.min.css | 0 .../static/bootstrap-2.1.1/css/bootstrap.css | 0 .../bootstrap-2.1.1/css/bootstrap.min.css | 0 .../img/glyphicons-halflings-white.png | Bin .../img/glyphicons-halflings.png | Bin .../static/bootstrap-2.1.1/js/bootstrap.js | 0 .../bootstrap-2.1.1/js/bootstrap.min.js | 0 binder/{files => }/static/bootstrap.css | 0 binder/templates/base.htm | 4 +- .../bcommon/delete_record_initial.htm | 2 +- binder/urls.py | 29 ++- binder/views.py | 152 ++++++++++++++++ manage.py | 10 ++ 25 files changed, 184 insertions(+), 247 deletions(-) rename binder/{bcommon => }/admin.py (85%) delete mode 100644 binder/bcommon/__init__.py delete mode 100644 binder/bcommon/tests.py delete mode 100644 binder/bcommon/views.py rename binder/{bcommon => }/forms.py (97%) rename binder/{bcommon => }/helpers.py (97%) rename binder/{bcommon => }/keyutils.py (91%) delete mode 100755 binder/manage.py rename binder/{bcommon => }/models.py (100%) rename binder/{files => }/static/bootstrap (100%) rename binder/{files => }/static/bootstrap-2.1.1/css/bootstrap-responsive.css (100%) rename binder/{files => }/static/bootstrap-2.1.1/css/bootstrap-responsive.min.css (100%) rename binder/{files => }/static/bootstrap-2.1.1/css/bootstrap.css (100%) rename binder/{files => }/static/bootstrap-2.1.1/css/bootstrap.min.css (100%) rename binder/{files => }/static/bootstrap-2.1.1/img/glyphicons-halflings-white.png (100%) rename binder/{files => }/static/bootstrap-2.1.1/img/glyphicons-halflings.png (100%) rename binder/{files => }/static/bootstrap-2.1.1/js/bootstrap.js (100%) rename binder/{files => }/static/bootstrap-2.1.1/js/bootstrap.min.js (100%) rename binder/{files => }/static/bootstrap.css (100%) create mode 100644 binder/views.py create mode 100755 manage.py diff --git a/binder/bcommon/admin.py b/binder/admin.py similarity index 85% rename from binder/bcommon/admin.py rename to binder/admin.py index 3b8cd80..699bf72 100644 --- a/binder/bcommon/admin.py +++ b/binder/admin.py @@ -1,4 +1,4 @@ -from bcommon.models import BindServer, Key +from models import BindServer, Key from django.contrib import admin class ZoneAdmin(admin.ModelAdmin): diff --git a/binder/bcommon/__init__.py b/binder/bcommon/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/binder/bcommon/tests.py b/binder/bcommon/tests.py deleted file mode 100644 index 2247054..0000000 --- a/binder/bcommon/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/binder/bcommon/views.py b/binder/bcommon/views.py deleted file mode 100644 index 0347a1c..0000000 --- a/binder/bcommon/views.py +++ /dev/null @@ -1,170 +0,0 @@ -# bcommon views - -from bcommon.models import BindServer, Key -from django.template import Context -from django.shortcuts import render_to_response, redirect, render -from bcommon.helpers import add_record, delete_record, add_cname_record - -from bcommon.forms import FormAddRecord, FormAddCnameRecord -from django.template import RequestContext -from bcommon.keyutils import create_keyring - -import re - -RE_UNICODEARRAY = re.compile(r"u'(.*?)'") - -def home_index(request): - return render_to_response('index.htm') - -def view_server_list(request): - """ List the DNS servers configured in the Django DB. """ - server_list = BindServer.objects.all().order_by('hostname') - return render_to_response('bcommon/list_servers.htm', - { "server_list" : server_list}, - context_instance=RequestContext(request)) - -def view_server_zones(request, dns_server): - """ Display the list of DNS zones a particular DNS host provides. """ - errors = "" - zone_array = {} - try: - this_server = BindServer.objects.get(hostname=dns_server) - zone_array = this_server.list_zones() - except BindServer.DoesNotExist, err: - errors = err - - if "errors" in zone_array: - errors = zone_array["errors"] - - return render_to_response('bcommon/list_server_zones.htm', - { "errors" : errors, - "dns_server" : dns_server, - "zone_array" : zone_array}) - -def view_zone_records(request, dns_server, zone_name): - """ Display the list of records for a a particular zone.""" - try: - this_server = BindServer.objects.get(hostname=dns_server) - zone_array = this_server.list_zone_records(zone_name) - except Exception, err: - # TODO: Use a custom exception here. - return render_to_response('bcommon/list_zone.htm', - { 'errors' : err}, - context_instance=RequestContext(request)) - - return render_to_response('bcommon/list_zone.htm', - { 'zone_array' : zone_array, - 'dns_server' : dns_server, - 'zone_name' : zone_name}, - context_instance=RequestContext(request)) - -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 }) - -def view_add_record_result(request): - """ Process the input given to add a DNS record. """ - errors = None - if request.method == "GET": - return redirect('/') - - form = FormAddRecord(request.POST) - if form.is_valid(): - cd = form.cleaned_data - try: - add_record_response = add_record(cd) - except BinderException, errors: - pass - return render_to_response('bcommon/add_record_result.htm', - { "errors" : errors, - "response" : add_record_response }, - context_instance=RequestContext(request)) - - return render(request, 'bcommon/add_record_form.htm', - { "dns_server" : request.POST["dns_server"], - "zone_name" : request.POST["zone_name"], - "form_errors" : form.errors, - "form_data" : request.POST }) - -def view_add_cname_record(request, dns_server, zone_name, record_name): - """ Process given input to add a CNAME pointer.""" - return render_to_response("bcommon/add_cname_record_form.htm", - { "dns_server" : dns_server, - "zone_name" : zone_name, - "record_name" : record_name, - "tsig_keys" : Key.objects.all() }, - context_instance=RequestContext(request)) - - -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 = 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 = 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_to_response('bcommon/add_cname_result.htm', - { 'errors' : err, - 'rr_data' : cd },) - - return render_to_response('bcommon/add_cname_result.htm', - { 'response' : add_cname_response, - 'rr_data' : cd }, - context_instance=RequestContext(request)) - - - -def view_delete_record(request): - if request.method == "GET": - # Return home. You shouldn't trying to directly acces - # the url for deleting records. - return redirect('/') - - dns_server = request.POST['dns_server'] - zone_name = request.POST['zone_name'] - rr_array = request.POST.getlist('rr_array') - - return render_to_response('bcommon/delete_record_initial.htm', - { 'dns_server' : dns_server, - 'zone_name' : zone_name, - 'rr_array' : rr_array, - 'tsig_keys' : Key.objects.all() }, - context_instance=RequestContext(request)) - - -def view_delete_result(request): - if request.method == "GET": - # Return home. You shouldn't trying to directly access - # the url for deleting records. - return redirect('/') - - # What seems like an ugly hack to get around the fact - # that the array comes back as Unicode values. - rr_unicode_array = request.POST.getlist('rr_array')[0] - rr_items = RE_UNICODEARRAY.findall(rr_unicode_array) - - try: - delete_result = delete_record(request.POST, rr_items) - except Exception, err: - return render_to_response('bcommon/delete_record_result.htm', - { "errors" : err }, - context_instance=RequestContext(request)) - - return render_to_response('bcommon/delete_record_result.htm', - { 'delete_result' : delete_result }, - context_instance=RequestContext(request)) diff --git a/binder/bcommon/forms.py b/binder/forms.py similarity index 97% rename from binder/bcommon/forms.py rename to binder/forms.py index 68cf768..3913d9e 100644 --- a/binder/bcommon/forms.py +++ b/binder/forms.py @@ -1,6 +1,6 @@ from django import forms -from bcommon.models import Key +from models import Key RECORD_TYPE_CHOICES = (("A", "A"), ("AAAA", "AAAA"), ("CNAME", "CNAME")) TTL_CHOICES = ((300, "5 minutes"), diff --git a/binder/bcommon/helpers.py b/binder/helpers.py similarity index 97% rename from binder/bcommon/helpers.py rename to binder/helpers.py index effeabb..34d013e 100644 --- a/binder/bcommon/helpers.py +++ b/binder/helpers.py @@ -1,4 +1,4 @@ -from bcommon.keyutils import create_keyring +import keyutils import re import dns.query @@ -100,7 +100,7 @@ def add_cname_record(dns_server, zone_name, originating_record, cname, ttl, key_ """Add a Cname record.""" if key_name is None: - keyring = create_keyring(key_name) + keyring = keyutils.create_keyring(key_name) else: keyring = None @@ -114,7 +114,7 @@ def delete_record(form_data, rr_items): """Delete a list of DNS records passed as strings in rr_items.""" if form_data["key_name"]: - keyring = create_keyring(form_data["key_name"]) + keyring = keyutils.create_keyring(form_data["key_name"]) else: keyring = None diff --git a/binder/bcommon/keyutils.py b/binder/keyutils.py similarity index 91% rename from binder/bcommon/keyutils.py rename to binder/keyutils.py index f35f739..5fef2a2 100755 --- a/binder/bcommon/keyutils.py +++ b/binder/keyutils.py @@ -1,6 +1,6 @@ import dns.tsigkeyring import sys -from bcommon.models import Key +from models import Key def create_keyring(key_name): """Accept a TSIG keyfile and a key name to retrieve. diff --git a/binder/manage.py b/binder/manage.py deleted file mode 100755 index bcdd55e..0000000 --- a/binder/manage.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python -from django.core.management import execute_manager -try: - import settings # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) - sys.exit(1) - -if __name__ == "__main__": - execute_manager(settings) diff --git a/binder/bcommon/models.py b/binder/models.py similarity index 100% rename from binder/bcommon/models.py rename to binder/models.py diff --git a/binder/settings.py b/binder/settings.py index 710c0f0..22d0bf6 100644 --- a/binder/settings.py +++ b/binder/settings.py @@ -21,13 +21,6 @@ DATABASES = { } } -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. TIME_ZONE = 'America/New_York' # Language code for this installation. All choices can be found here: @@ -36,12 +29,7 @@ LANGUAGE_CODE = 'en-us' SITE_ID = 1 -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. USE_I18N = True - -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale USE_L10N = True # Absolute path to the directory that holds media. @@ -52,10 +40,8 @@ MEDIA_ROOT = os.path.join(SITE_ROOT, "files") # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" MEDIA_URL = "/files/" +STATIC_URL= "/static/" -STATIC_URL = '/media/' - -# Make this unique, and don't share it with anybody. SECRET_KEY = 'iuo-zka8nnv0o+b*7#_*fcep$@f^35=)c#7_20z6i8g0oc&r!g' # List of callables that know how to import templates from various sources. @@ -86,5 +72,5 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.admin', 'django.contrib.staticfiles', - 'bcommon', + 'binder', ) diff --git a/binder/files/static/bootstrap b/binder/static/bootstrap similarity index 100% rename from binder/files/static/bootstrap rename to binder/static/bootstrap diff --git a/binder/files/static/bootstrap-2.1.1/css/bootstrap-responsive.css b/binder/static/bootstrap-2.1.1/css/bootstrap-responsive.css similarity index 100% rename from binder/files/static/bootstrap-2.1.1/css/bootstrap-responsive.css rename to binder/static/bootstrap-2.1.1/css/bootstrap-responsive.css diff --git a/binder/files/static/bootstrap-2.1.1/css/bootstrap-responsive.min.css b/binder/static/bootstrap-2.1.1/css/bootstrap-responsive.min.css similarity index 100% rename from binder/files/static/bootstrap-2.1.1/css/bootstrap-responsive.min.css rename to binder/static/bootstrap-2.1.1/css/bootstrap-responsive.min.css diff --git a/binder/files/static/bootstrap-2.1.1/css/bootstrap.css b/binder/static/bootstrap-2.1.1/css/bootstrap.css similarity index 100% rename from binder/files/static/bootstrap-2.1.1/css/bootstrap.css rename to binder/static/bootstrap-2.1.1/css/bootstrap.css diff --git a/binder/files/static/bootstrap-2.1.1/css/bootstrap.min.css b/binder/static/bootstrap-2.1.1/css/bootstrap.min.css similarity index 100% rename from binder/files/static/bootstrap-2.1.1/css/bootstrap.min.css rename to binder/static/bootstrap-2.1.1/css/bootstrap.min.css diff --git a/binder/files/static/bootstrap-2.1.1/img/glyphicons-halflings-white.png b/binder/static/bootstrap-2.1.1/img/glyphicons-halflings-white.png similarity index 100% rename from binder/files/static/bootstrap-2.1.1/img/glyphicons-halflings-white.png rename to binder/static/bootstrap-2.1.1/img/glyphicons-halflings-white.png diff --git a/binder/files/static/bootstrap-2.1.1/img/glyphicons-halflings.png b/binder/static/bootstrap-2.1.1/img/glyphicons-halflings.png similarity index 100% rename from binder/files/static/bootstrap-2.1.1/img/glyphicons-halflings.png rename to binder/static/bootstrap-2.1.1/img/glyphicons-halflings.png diff --git a/binder/files/static/bootstrap-2.1.1/js/bootstrap.js b/binder/static/bootstrap-2.1.1/js/bootstrap.js similarity index 100% rename from binder/files/static/bootstrap-2.1.1/js/bootstrap.js rename to binder/static/bootstrap-2.1.1/js/bootstrap.js diff --git a/binder/files/static/bootstrap-2.1.1/js/bootstrap.min.js b/binder/static/bootstrap-2.1.1/js/bootstrap.min.js similarity index 100% rename from binder/files/static/bootstrap-2.1.1/js/bootstrap.min.js rename to binder/static/bootstrap-2.1.1/js/bootstrap.min.js diff --git a/binder/files/static/bootstrap.css b/binder/static/bootstrap.css similarity index 100% rename from binder/files/static/bootstrap.css rename to binder/static/bootstrap.css diff --git a/binder/templates/base.htm b/binder/templates/base.htm index 91f9c1c..f30e648 100644 --- a/binder/templates/base.htm +++ b/binder/templates/base.htm @@ -3,7 +3,7 @@ {% block header %} Binder DNS Admin - + {% endblock header %} @@ -22,7 +22,7 @@
- +