diff --git a/forms.py b/forms.py index dd3e0f3..94558c3 100644 --- a/forms.py +++ b/forms.py @@ -21,22 +21,6 @@ from django.utils.translation import gettext as _ from fieldset_forms import FieldsetForm -#Redefined Classes for Validation Purpose -class DomainField(forms.EmailField): - def validate(self, value): - "Check if value consists of a valid email domain." - mail = "mail@"+value - super(DomainField, self).validate(mail) - validate_email(mail) - - -class ListNameField(forms.EmailField): - def validate(self, value): - "Check if value consists of a valid email prefix." - mail = value+"@example.net" - super(ListNameField, self).validate(mail) - validate_email(mail) - #Fieldsets for use within the views class DomainNew(FieldsetForm): """ @@ -122,7 +106,7 @@ ("Turkish", "Turkish"), ("Ukrainian", "Ukrainian"), ("Vietnamese", "Vietnamese")) - listname = ListNameField( + listname = forms.CharField( label = _('List Name'), required = True, error_messages = {'required': _('Please enter a name for your list.'), @@ -156,21 +140,26 @@ description = forms.CharField( label = _('Description'), - widget = forms.TextInput(), required = True) - - web_host = forms.ChoiceField( ) - + + web_host = forms.ChoiceField() + def __init__(self,domain_choices, *args, **kwargs): super(ListNew, self).__init__(*args, **kwargs) self.fields["web_host"] = forms.ChoiceField( widget = forms.Select(), - label = _('Web Host'), + label = _('Mail Host'), required = True, choices = domain_choices, error_messages = {'required': _("Choose an existing Domain."),} - ) - + ) + def clean_listname(self): + try: + validate_email(self.cleaned_data['listname']+'@example.net') + except: + raise forms.ValidationError(_("Please enter a valid listname (my-list-1)")) + return self.cleaned_data['listname'] + class Meta: """ Class to handle the automatic insertion of fieldsets and divs. diff --git a/views.py b/views.py index 9de3b92..721ee04 100644 --- a/views.py +++ b/views.py @@ -114,8 +114,17 @@ be logged in to create a new list. """ if request.method == 'POST': - form = ListNew(request.POST) + try: + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) + except Exception, e: + return HttpResponse(e) + choosable_domains = [("",_("Choose a Domain"))] + for domain in c.domains: + choosable_domains.append((domain.email_host,domain.email_host)) + form = ListNew(choosable_domains,request.POST) + if form.is_valid(): + try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) except Exception, e: @@ -140,9 +149,9 @@ return HttpResponse(e) choosable_domains = [("",_("Choose a Domain"))] for domain in c.domains: - choosable_domains.append((domain.url_host,domain.url_host)) + choosable_domains.append((domain.email_host,domain.email_host)) form = ListNew(choosable_domains) - + return render_to_response(template, {'form': form})