diff --git a/src/postorius/forms.py b/src/postorius/forms.py index cab04b4..58244e8 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -17,7 +17,7 @@ # Postorius. If not, see . from django import forms -from django.core.validators import validate_email, URLValidator +from django.core.validators import validate_email from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ from postorius.fieldset_forms import FieldsetForm diff --git a/src/postorius/tests/mailman_api_tests/test_list_summary.py b/src/postorius/tests/mailman_api_tests/test_list_summary.py index 344c5e6..5de95d6 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_summary.py +++ b/src/postorius/tests/mailman_api_tests/test_list_summary.py @@ -105,7 +105,7 @@ response = self.client.get(reverse('list_summary', args=('foo@example.com', ))) self.assertEqual(response.status_code, 200) - self.assertTrue('Change Subscription' in response.content) + self.assertTrue('Change subscription' in response.content) self.assertTrue('Unsubscribe' in response.content) @MM_VCR.use_cassette('test_list_summary_owner.yaml') diff --git a/src/postorius/tests/test_forms.py b/src/postorius/tests/test_forms.py index f5cb781..bc511fb 100644 --- a/src/postorius/tests/test_forms.py +++ b/src/postorius/tests/test_forms.py @@ -45,7 +45,7 @@ def test_form_fields_webhost_invalid(self): form = DomainNew({ 'mail_host': 'mailman.most-desirable.org', - 'web_host': 'mailman.most-desirable.org', + 'web_host': 'most-desirable', 'description': 'The Most Desirable organization', 'contact_address': 'contact@mailman.most-desirable.org', }) diff --git a/src/postorius/urls.py b/src/postorius/urls.py index f599d4f..5c9a3cc 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -105,7 +105,7 @@ url(r'^accounts/mailmansettings/$', UserMailmanSettingsView.as_view(), name='user_mailmansettings'), - # /settings/ + # /domains/ url(r'^domains/$', 'domain_index', name='domain_index'), url(r'^domains/new/$', 'domain_new', name='domain_new'), url(r'^domains/(?P[^/]+)/delete$', diff --git a/src/postorius/views/__init__.py b/src/postorius/views/__init__.py index 43bdce6..c1dccfd 100644 --- a/src/postorius/views/__init__.py +++ b/src/postorius/views/__init__.py @@ -18,5 +18,5 @@ from postorius.views.api import * from postorius.views.list import * -from postorius.views.settings import * +from postorius.views.domain import * from postorius.views.user import * diff --git a/src/postorius/views/domain.py b/src/postorius/views/domain.py new file mode 100644 index 0000000..ff574ba --- /dev/null +++ b/src/postorius/views/domain.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2015 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see . + + +import json + + +from django.conf import settings +from django.contrib import messages +from django.contrib.auth import logout, authenticate, login +from django.contrib.auth.decorators import (login_required, + permission_required, + user_passes_test) +from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, + SetPasswordForm, PasswordChangeForm) +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render_to_response, redirect +from django.template import Context, loader, RequestContext +from django.utils.decorators import method_decorator +from django.utils.translation import gettext as _ +try: + from urllib2 import HTTPError +except ImportError: + from urllib.error import HTTPError +from postorius import utils +from postorius.models import (Domain, List, Member, MailmanUser, + MailmanApiError, Mailman404Error) +from postorius.forms import * +from postorius.auth.decorators import * + + +@login_required +@user_passes_test(lambda u: u.is_superuser) +def domain_index(request): + try: + existing_domains = Domain.objects.all() + except MailmanApiError: + return utils.render_api_error(request) + return render_to_response('postorius/domain/index.html', + {'domains': existing_domains}, + context_instance=RequestContext(request)) + + +@login_required +@user_passes_test(lambda u: u.is_superuser) +def domain_new(request): + message = None + if request.method == 'POST': + form = DomainNew(request.POST) + if form.is_valid(): + domain = Domain(mail_host=form.cleaned_data['mail_host'], + base_url=form.cleaned_data['web_host'], + description=form.cleaned_data['description'], + owner=request.user.email) + try: + domain.save() + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError as e: + messages.error(request, e) + else: + messages.success(request, _("New Domain registered")) + return redirect("domain_index") + else: + form = DomainNew() + return render_to_response('postorius/domain/new.html', + {'form': form, 'message': message}, + context_instance=RequestContext(request)) + + +def domain_delete(request, domain): + """Deletes a domain but asks for confirmation first. + """ + if request.method == 'POST': + try: + client = utils.get_client() + client.delete_domain(domain) + messages.success(request, + _('The domain %s has been deleted.' % domain)) + return redirect("domain_index") + except HTTPError as e: + messages.error(request, _('The domain could not be deleted:' + ' %s' % e.msg)) + return redirect("domain_index") + submit_url = reverse('domain_delete', + kwargs={'domain': domain}) + return render_to_response('postorius/domain/confirm_delete.html', + {'domain': domain, 'submit_url': submit_url}, + context_instance=RequestContext(request)) diff --git a/src/postorius/views/settings.py b/src/postorius/views/settings.py deleted file mode 100644 index ff574ba..0000000 --- a/src/postorius/views/settings.py +++ /dev/null @@ -1,106 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 1998-2015 by the Free Software Foundation, Inc. -# -# This file is part of Postorius. -# -# Postorius is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# Postorius is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# Postorius. If not, see . - - -import json - - -from django.conf import settings -from django.contrib import messages -from django.contrib.auth import logout, authenticate, login -from django.contrib.auth.decorators import (login_required, - permission_required, - user_passes_test) -from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, - SetPasswordForm, PasswordChangeForm) -from django.contrib.auth.models import User -from django.core.urlresolvers import reverse -from django.http import HttpResponse, HttpResponseRedirect -from django.shortcuts import render_to_response, redirect -from django.template import Context, loader, RequestContext -from django.utils.decorators import method_decorator -from django.utils.translation import gettext as _ -try: - from urllib2 import HTTPError -except ImportError: - from urllib.error import HTTPError -from postorius import utils -from postorius.models import (Domain, List, Member, MailmanUser, - MailmanApiError, Mailman404Error) -from postorius.forms import * -from postorius.auth.decorators import * - - -@login_required -@user_passes_test(lambda u: u.is_superuser) -def domain_index(request): - try: - existing_domains = Domain.objects.all() - except MailmanApiError: - return utils.render_api_error(request) - return render_to_response('postorius/domain/index.html', - {'domains': existing_domains}, - context_instance=RequestContext(request)) - - -@login_required -@user_passes_test(lambda u: u.is_superuser) -def domain_new(request): - message = None - if request.method == 'POST': - form = DomainNew(request.POST) - if form.is_valid(): - domain = Domain(mail_host=form.cleaned_data['mail_host'], - base_url=form.cleaned_data['web_host'], - description=form.cleaned_data['description'], - owner=request.user.email) - try: - domain.save() - except MailmanApiError: - return utils.render_api_error(request) - except HTTPError as e: - messages.error(request, e) - else: - messages.success(request, _("New Domain registered")) - return redirect("domain_index") - else: - form = DomainNew() - return render_to_response('postorius/domain/new.html', - {'form': form, 'message': message}, - context_instance=RequestContext(request)) - - -def domain_delete(request, domain): - """Deletes a domain but asks for confirmation first. - """ - if request.method == 'POST': - try: - client = utils.get_client() - client.delete_domain(domain) - messages.success(request, - _('The domain %s has been deleted.' % domain)) - return redirect("domain_index") - except HTTPError as e: - messages.error(request, _('The domain could not be deleted:' - ' %s' % e.msg)) - return redirect("domain_index") - submit_url = reverse('domain_delete', - kwargs={'domain': domain}) - return render_to_response('postorius/domain/confirm_delete.html', - {'domain': domain, 'submit_url': submit_url}, - context_instance=RequestContext(request))