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.
This commit is contained in:
Daniel Roschka 2015-03-29 12:16:57 +02:00
parent 41f78b3eff
commit 581dc915fe
5 changed files with 27 additions and 22 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
*.conf
*~
/binder/secret.txt
/binder/local_settings.py

View File

@ -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):

View File

@ -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"))

View File

@ -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

View File

@ -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() })