From 581dc915fe54822148ed89698208e27c75a5ca54 Mon Sep 17 00:00:00 2001 From: Daniel Roschka Date: Sun, 29 Mar 2015 12:16:57 +0200 Subject: [PATCH] Change in the behavior of local_settings.py Up to now local_settings.py was used for binder specific configuration values. This commit moves these values to settings.py, removes local_settings.py from version control and adds logic to settings.py to allow settings in local_settings.py to overwrite ones defined in settings.py, enabling local_settings.py to be used as installation specific configuration file, e.g. for custom database configuration. --- .gitignore | 1 + binder/forms.py | 10 +++++----- binder/local_settings.py | 10 ---------- binder/settings.py | 14 ++++++++++++++ binder/views.py | 14 +++++++------- 5 files changed, 27 insertions(+), 22 deletions(-) delete mode 100644 binder/local_settings.py diff --git a/.gitignore b/.gitignore index 83e5248..77b76b0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.conf *~ /binder/secret.txt +/binder/local_settings.py diff --git a/binder/forms.py b/binder/forms.py index 420205b..ef9c040 100644 --- a/binder/forms.py +++ b/binder/forms.py @@ -2,11 +2,11 @@ # 3rd Party from django import forms +from django.conf import settings from django.forms import ValidationError # App Imports from models import Key -import local_settings ### Custom Form Fields @@ -40,10 +40,10 @@ class FormAddForwardRecord(forms.Form): """ Form used to add a Forward DNS record. """ dns_server = forms.CharField(max_length=100) record_name = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$", required=False) - record_type = forms.ChoiceField(choices=local_settings.RECORD_TYPE_CHOICES) + record_type = forms.ChoiceField(choices=settings.RECORD_TYPE_CHOICES) zone_name = forms.CharField(max_length=100) record_data = forms.GenericIPAddressField() - ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES) + ttl = forms.ChoiceField(choices=settings.TTL_CHOICES) create_reverse = forms.BooleanField(required=False) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) @@ -54,7 +54,7 @@ class FormAddReverseRecord(forms.Form): record_type = forms.RegexField(regex=r"^PTR$",error_messages={"invalid" : "The only valid choice here is PTR."}) zone_name = forms.CharField(max_length=100) record_data = CustomStringPeriodSuffix(required=True) - ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES) + ttl = forms.ChoiceField(choices=settings.TTL_CHOICES) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) create_reverse = forms.BooleanField(required=False) @@ -64,7 +64,7 @@ class FormAddCnameRecord(forms.Form): originating_record = forms.CharField(max_length=100) cname = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$") zone_name = forms.CharField(max_length=256) - ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES) + ttl = forms.ChoiceField(choices=settings.TTL_CHOICES) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) class FormDeleteRecord(forms.Form): diff --git a/binder/local_settings.py b/binder/local_settings.py deleted file mode 100644 index a7a7f32..0000000 --- a/binder/local_settings.py +++ /dev/null @@ -1,10 +0,0 @@ -### Local settings to be shared across modules. - -TTL_CHOICES = ((300, "5 minutes"), - (1800, "30 minutes"), - (3600, "1 hour"), - (43200, "12 hours"), - (86400, "1 day")) - -RECORD_TYPE_CHOICES = (("A", "A"), - ("AAAA", "AAAA")) diff --git a/binder/settings.py b/binder/settings.py index a787a6a..b88d131 100644 --- a/binder/settings.py +++ b/binder/settings.py @@ -86,3 +86,17 @@ INSTALLED_APPS = ( ) TEST_RUNNER = 'django.test.runner.DiscoverRunner' + +TTL_CHOICES = ((300, "5 minutes"), + (1800, "30 minutes"), + (3600, "1 hour"), + (43200, "12 hours"), + (86400, "1 day")) + +RECORD_TYPE_CHOICES = (("A", "A"), + ("AAAA", "AAAA")) + +try: + from local_settings import * +except ImportError: + pass diff --git a/binder/views.py b/binder/views.py index 7047df1..595bdcc 100644 --- a/binder/views.py +++ b/binder/views.py @@ -1,11 +1,11 @@ ### Binder VIews # 3rd Party +from django.conf import settings from django.shortcuts import redirect, render # App Imports from binder import exceptions, forms, helpers, models -import local_settings def home_index(request): """ List the main index page for Binder. """ @@ -73,8 +73,8 @@ def view_add_record(request, dns_server, zone_name): { "dns_server" : this_server, "zone_name" : zone_name, "tsig_keys" : models.Key.objects.all(), - "ttl_choices" : local_settings.TTL_CHOICES, - "record_type_choices" : local_settings.RECORD_TYPE_CHOICES, + "ttl_choices": settings.TTL_CHOICES, + "record_type_choices": settings.RECORD_TYPE_CHOICES, }) @@ -119,8 +119,8 @@ def view_add_record_result(request): { "dns_server" : dns_server, "zone_name" : request.POST["zone_name"], "tsig_keys" : models.Key.objects.all(), - "ttl_choices" : local_settings.TTL_CHOICES, - "record_type_choices" : local_settings.RECORD_TYPE_CHOICES, + "ttl_choices": settings.TTL_CHOICES, + "record_type_choices": settings.RECORD_TYPE_CHOICES, "form_errors" : form.errors, "form_data" : request.POST }) @@ -134,7 +134,7 @@ def view_add_cname_record(request, dns_server, zone_name, record_name): { "dns_server" : this_server, "originating_record" : "%s.%s" % (record_name, zone_name), "zone_name" : zone_name, - "ttl_choices" : local_settings.TTL_CHOICES, + "ttl_choices": settings.TTL_CHOICES, "tsig_keys" : models.Key.objects.all() }) @@ -172,7 +172,7 @@ def view_add_cname_result(request): "originating_record" : request.POST["originating_record"], "form_data" : request.POST, "form_errors" : form.errors, - "ttl_choices" : local_settings.TTL_CHOICES, + "ttl_choices": settings.TTL_CHOICES, "tsig_keys" : models.Key.objects.all() })