diff --git a/forms.py b/forms.py index 6ba4628..5fb169f 100644 --- a/forms.py +++ b/forms.py @@ -20,6 +20,34 @@ from django.utils.translation import gettext as _ from fieldset_forms import FieldsetForm +class DomainNew(FieldsetForm): + """ + Form field to add a new domain + """ + domain_name = forms.CharField( + label = _('Domain Name'), + required = True, + ) + contact_address = forms.EmailField( + label = _('Your email address'), + error_messages = {'required': _('Please enter an email address.'), + 'invalid': _('Please enter a valid email address.')}) + description = forms.CharField( + label = _('Description'), + required = False, + ) + class Meta: + """ + Class to handle the automatic insertion of fieldsets and divs. + + To use it: add a list for each wished fieldset. The first item in + the list should be the wished name of the fieldset, the following + the fields that should be included in the fieldset. + """ + layout = [["New Domain","domain_name", "contact_address",], + ["Description", "description"]] + + class ListNew(FieldsetForm): """ Form fields to add a new list. Languages are hard coded which should diff --git a/templates/mailman-django/base.html b/templates/mailman-django/base.html index 9902349..e70f24f 100644 --- a/templates/mailman-django/base.html +++ b/templates/mailman-django/base.html @@ -40,6 +40,10 @@ {% endblocktrans %} {% block links %}{% endblock %}

+ Testing + {% block content %}{% endblock %} diff --git a/urls.py b/urls.py index 3abb936..7b2fe66 100644 --- a/urls.py +++ b/urls.py @@ -21,6 +21,7 @@ urlpatterns = patterns('mailman_django.views', (r'^$', 'list_index'), + url(r'^new_domain', 'new_domain', name = 'new_domain'), url(r'^lists/$', 'list_index', name = 'list_index'), url(r'^lists/new/$', 'list_new', name = 'list_new'), url(r'^lists/logout/$', 'logout', name = 'logout'), diff --git a/views.py b/views.py index 7a9dd54..2a7237d 100644 --- a/views.py +++ b/views.py @@ -77,6 +77,29 @@ return _login_decorator #@login_required +def new_domain(request, template = 'mailman-django/new_domain.html'): + if request.method == 'POST': + form = DomainNew(request.POST) + if form.is_valid(): + 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) + + else: + try: + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) + existing_domains = c.domains + except Exception, e: + return HttpResponse(e) + form = DomainNew() + return render_to_response(template, {'form': form,'domains':existing_domains}) + +#@login_required def list_new(request, template = 'mailman-django/lists/new.html'): """ Add a new mailing list. @@ -92,7 +115,7 @@ if form.is_valid(): listname = form.cleaned_data['listname'] try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) except Exception, e: return HttpResponse(e) @@ -122,13 +145,13 @@ """Show a table of all mailing lists. """ try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) except: return render_to_response('mailman-django/errors/generic.html', {'message': "Unexpected error:"+ str(sys.exc_info()[0])}) try: - lists = c.get_lists() + lists = c.lists return render_to_response(template, {'lists': lists}) except: return render_to_response('mailman-django/errors/generic.html', @@ -144,7 +167,7 @@ user to fill in which are evaluated in this function. """ try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) the_list = c.get_list(fqdn_listname) except Exception, e: return HttpResponse(e) @@ -211,7 +234,7 @@ # create a connection to Mailman and get the list try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) the_list = c.get_list(fqdn_listname) except Exception, e: return HttpResponse(e) @@ -237,7 +260,7 @@ """ message = "" try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) the_list = c.get_list(fqdn_listname) except Exception, e: return HttpResponse(e) @@ -262,7 +285,7 @@ """ message = "" try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) the_list = c.get_list(fqdn_listname) except Exception, e: return HttpResponse(e) @@ -308,7 +331,7 @@ membership_lists = [] listname = "" try: - c = Client('localhost:8001', API_USER, API_PASS) + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) user_object = c.get_user(member) # address_choices for the 'address' field must be a list of # tuples of length 2