diff --git a/fieldset_forms.py b/fieldset_forms.py index bcfbafa..3f0c773 100644 --- a/fieldset_forms.py +++ b/fieldset_forms.py @@ -19,6 +19,7 @@ from django.forms import Form from django.utils import safestring from django.forms.forms import BoundField +from django.forms.util import ErrorList class FieldsetError(Exception): pass @@ -41,12 +42,14 @@ else: self.layout = [["All"]] self.layout[0][1:]=(self.fields.keys()) - #raise Exception(self.layout)#debug def as_div(self): """Render the form as a set of
s.""" output = "" - # first, create the fieldsets + #Adding Errors + try: output += str(self.errors["NON_FIELD_ERRORS"]) + except: pass + #create the fieldsets for index in range(len(self.layout)): output += self.create_fieldset(self.layout[index]) return safestring.mark_safe(output) diff --git a/forms.py b/forms.py index 94558c3..98279d8 100644 --- a/forms.py +++ b/forms.py @@ -116,7 +116,6 @@ label = _('Inital list owner address'), error_messages = { 'required': _("Please enter the list owner's email address."), - 'invalid': _('Please enter a valid email adress.') }, required = True) list_type = forms.ChoiceField( @@ -137,22 +136,24 @@ widget = forms.CheckboxSelectMultiple(), choices = languages, required = False) - + description = forms.CharField( label = _('Description'), required = True) - web_host = forms.ChoiceField() + mail_host = forms.ChoiceField() def __init__(self,domain_choices, *args, **kwargs): super(ListNew, self).__init__(*args, **kwargs) - self.fields["web_host"] = forms.ChoiceField( + self.fields["mail_host"] = forms.ChoiceField( widget = forms.Select(), label = _('Mail Host'), required = True, choices = domain_choices, - error_messages = {'required': _("Choose an existing Domain."),} + error_messages = {'required': _("Choose an existing Domain."), + 'invalid':"ERROR-todo_forms.py" }#todo ) + def clean_listname(self): try: validate_email(self.cleaned_data['listname']+'@example.net') @@ -168,7 +169,7 @@ the list should be the wished name of the fieldset, the following the fields that should be included in the fieldset. """ - layout = [["List Details", "listname", "web_host", "list_owner", "description", "list_type"], + layout = [["List Details", "listname", "mail_host", "list_owner", "description", "list_type"], ["Available Languages", "languages"]] class ListSubscribe(forms.Form): diff --git a/templates/mailman-django/lists/new.html b/templates/mailman-django/lists/new.html index cfa9b91..e8cc479 100644 --- a/templates/mailman-django/lists/new.html +++ b/templates/mailman-django/lists/new.html @@ -8,9 +8,7 @@

{% trans "Logout" %}

- {{ form.as_div }} -
diff --git a/views.py b/views.py index 721ee04..052096c 100644 --- a/views.py +++ b/views.py @@ -88,7 +88,11 @@ mail_host = form.cleaned_data['mail_host'] web_host = form.cleaned_data['web_host'] description = form.cleaned_data['description'] - domain = c.create_domain(mail_host,web_host,description) + try: + domain = c.create_domain(mail_host,web_host,description) + except Exception, e: + form._errors["NON_FIELD_ERRORS"]=forms.util.ErrorList() + form._errors["NON_FIELD_ERRORS"].append(e) else: try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) @@ -124,13 +128,19 @@ form = ListNew(choosable_domains,request.POST) if form.is_valid(): - + #connect and grab domain try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) except Exception, e: return HttpResponse(e) - domain = c.get_domain(form.cleaned_data['web_host']) - mailing_list = domain.create_list(form.cleaned_data['listname']) + domain = c.get_domain(form.cleaned_data['mail_host']) + #creating the list + try: + mailing_list = domain.create_list(form.cleaned_data['listname']) + except Exception, e: + form._errors["NON_FIELD_ERRORS"]=forms.util.ErrorList() + form._errors["NON_FIELD_ERRORS"].append(e) + #saving settings """settings = mailing_list.settings settings["description"] = form.cleaned_data['description'] #settings["owner_address"] = form.cleaned_data['list_owner'] #TODO: Readonly @@ -138,8 +148,9 @@ #settings["???"] = form.cleaned_data['languages'] #TODO not found in REST settings.save()""" try: - return render_to_response('mailman-django/lists/created.html', - {'fqdn_listname': mailing_list.info['fqdn_listname']}) + pass #debug + #return render_to_response('mailman-django/lists/created.html', + # {'fqdn_listname': mailing_list.info['fqdn_listname']}) except Exception, e: return HttpResponse(e) else: