diff --git a/forms.py b/forms.py index 5fb169f..44c2e5a 100644 --- a/forms.py +++ b/forms.py @@ -87,10 +87,23 @@ ("Turkish", "Turkish"), ("Ukrainian", "Ukrainian"), ("Vietnamese", "Vietnamese")) - listname = forms.EmailField( + listname = forms.CharField( label = _('List Name'), + required = True, error_messages = {'required': _('Please enter a name for your list.'), - 'invalid': _('Please enter a valid list name.')}) + 'invalid': _('Please enter a valid list name.')} + ) + domains = forms.ChoiceField( + widget = forms.Select(), + label = _('@Domain'), + required = True, + choices = ( ("",("Please Choose a Domain")), + ("example.com",("http://example.com")),#NEEDS to be REST API Call + ), + error_messages = { + 'required': _("Please choose an existing Domain."), + } + ) list_owner = forms.EmailField( label = _('Inital list owner address'), error_messages = { @@ -110,6 +123,7 @@ ("closed_discussion", _("Closed discussion list")), ("announcement", _("Announcement list")), )) + languages = forms.MultipleChoiceField( label = _('Language'), widget = forms.CheckboxSelectMultiple(), @@ -124,7 +138,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", "list_owner", "list_type"], + layout = [["List Details", "listname", "domains", "list_owner", "list_type"], ["Available Languages", "languages"]] class ListSubscribe(forms.Form): diff --git a/views.py b/views.py index 2a7237d..7738cdd 100644 --- a/views.py +++ b/views.py @@ -84,11 +84,11 @@ domain_name = form.cleaned_data['domain_name'] try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) - domain = c.create_domain(domain_name) - domain.contact_address = form.cleaned_data['contact_address'] - domain.description = form.cleaned_data['description'] except Exception, e: return HttpResponse(e) + domain = c.create_domain(domain_name) + domain.contact_address = form.cleaned_data['contact_address'] + domain.description = form.cleaned_data['description'] else: try: @@ -113,30 +113,28 @@ if request.method == 'POST': form = ListNew(request.POST) if form.is_valid(): - listname = form.cleaned_data['listname'] 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['domains']) + mailing_list = domain.create_list(form.cleaned_data['listname']) - parts = listname.split('@') - domain = c.get_domain(parts[1]) - if domain.info == 404: # failed to get domain so try - # creating a new one - try: - domain = c.create_domain(parts[1]) - except: - # I don't think this error can ever appear. -- Anna - return HttpResponse(e) try: - response = domain.create_list(parts[0]) return render_to_response('mailman-django/lists/created.html', - {'fqdn_listname': response.info['fqdn_listname']}) - except: + {'fqdn_listname': mailing_list.info['fqdn_listname']}) + except Exception, e: return HttpResponse(e) else: form = ListNew() + try: + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) + #form.domains.choices = c.domains + except Exception, e: + return HttpResponse(e) + return render_to_response(template, {'form': form}) @@ -146,16 +144,16 @@ """ try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) - except: + except Exception, e: return render_to_response('mailman-django/errors/generic.html', - {'message': "Unexpected error:"+ str(sys.exc_info()[0])}) + {'message': "Unexpected error:"+ e}) try: lists = c.lists return render_to_response(template, {'lists': lists}) - except: + except Exception, e: return render_to_response('mailman-django/errors/generic.html', - {'message': "Unexpected error:"+ str(sys.exc_info()[0])}) + {'message': "Unexpected error:"+ e}) def list_info(request, fqdn_listname = None, @@ -246,9 +244,9 @@ try: lists = c.get_lists() return render_to_response(template, {'lists': lists}) - except: + except Exception, e: return render_to_response('mailman-django/errors/generic.html', - {'message': "Unexpected error:"+ str(sys.exc_info()[0])}) + {'message': "Unexpected error:"+ e}) @login_required def list_settings(request, fqdn_listname = None,