create local_settings, pass TTL_CHOICES around to be able to pick TTL when creating record.

This commit is contained in:
Jeffrey Forman 2012-12-02 08:49:49 -05:00
parent a3f0a643a1
commit 42db5cedee
5 changed files with 29 additions and 13 deletions

View File

@ -6,14 +6,7 @@ from django.core.exceptions import ValidationError
# App Imports
from models import Key
TTL_CHOICES = ((300, "5 minutes"),
(1800, "30 minutes"),
(3600, "1 hour"),
(43200, "12 hours"),
(86400, "1 day"))
RECORD_TYPE_CHOICES = (("A", "A"), ("AAAA", "AAAA"), ("CNAME", "CNAME"))
import local_settings
### Custom Form Fields
@ -37,7 +30,7 @@ class FormAddRecord(forms.Form):
record_type = forms.CharField(max_length=10)
zone_name = forms.CharField(max_length=100)
record_data = forms.GenericIPAddressField()
ttl = forms.IntegerField(min_value=1)
ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES)
create_reverse = forms.BooleanField(required=False)
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False)
@ -48,7 +41,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=TTL_CHOICES)
ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES)
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False)
class FormDeleteRecord(forms.Form):

11
binder/local_settings.py Normal file
View File

@ -0,0 +1,11 @@
### 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"),
("CNAME", "CNAME"))

View File

@ -42,7 +42,11 @@ Add CNAME record for {{ originating_record }}
<label class="control-label">TTL: </label>
<div class="controls">
<select name="ttl">
<option value="86400">86400 (1 day)</option>
{% for ttl, description in ttl_choices %}
<option value="{{ttl}}">
{{ttl}} ({{description}})
</option>
{% endfor %}
</select>
</div>
</div>

View File

@ -60,7 +60,11 @@ Add record in {{ zone_name }}
<label class="control-label">TTL: </label>
<div class="controls">
<select name="ttl">
<option value="86400">86400 (1 day)</option>
{% for ttl, description in ttl_choices %}
<option value="{{ttl}}">
{{ttl}} ({{description}})
</option>
{% endfor %}
</select>
</div>
</div>

View File

@ -5,6 +5,7 @@ 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. """
@ -63,7 +64,9 @@ def view_add_record(request, dns_server, zone_name):
return render(request, "bcommon/add_record_form.htm",
{ "dns_server" : dns_server,
"zone_name" : zone_name,
"tsig_keys" : models.Key.objects.all() })
"tsig_keys" : models.Key.objects.all(),
"ttl_choices" : local_settings.TTL_CHOICES,
})
def view_add_record_result(request):
""" Process the input given to add a DNS record. """
@ -104,6 +107,7 @@ def view_add_cname_record(request, dns_server, zone_name, record_name):
{ "dns_server" : dns_server,
"originating_record" : "%s.%s" % (record_name, zone_name),
"zone_name" : zone_name,
"ttl_choices" : local_settings.TTL_CHOICES,
"tsig_keys" : models.Key.objects.all() })
def view_add_cname_result(request):