From 8858d831b1b5c2c8d1fc8d11275e7d44487c8658 Mon Sep 17 00:00:00 2001 From: Jeffrey Forman Date: Fri, 23 Nov 2012 22:21:41 -0500 Subject: [PATCH] add a delete form model. add custom field for converting unicode to string list --- binder/forms.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/binder/forms.py b/binder/forms.py index f1e54b8..5640ad7 100644 --- a/binder/forms.py +++ b/binder/forms.py @@ -1,14 +1,31 @@ from django import forms from models import Key -RECORD_TYPE_CHOICES = (("A", "A"), ("AAAA", "AAAA"), ("CNAME", "CNAME")) 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")) + +### Custom Form Fields + +class CustomUnicodeListField(forms.CharField): + """ Convert unicode item list to list of strings. """ + def clean(self, value): + try: + first_parse = eval(value) + string_list = [current_item for current_item in first_parse] + except: + raise ValidationError + + return string_list + +### Form Models + class FormAddRecord(forms.Form): + """ Form used to add a 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.CharField(max_length=10) @@ -20,9 +37,17 @@ class FormAddRecord(forms.Form): class FormAddCnameRecord(forms.Form): + """ Form used to add a CNAME record. """ dns_server = forms.CharField(max_length=100) 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) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) + +class FormDeleteRecord(forms.Form): + """ Final form to delete DNS record(s). """ + dns_server = forms.CharField(max_length=100) + zone_name = forms.CharField(max_length=256) + rr_list = CustomUnicodeListField(required=False) + key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False)