Commit da73ac36 authored by Simon Hanna's avatar Simon Hanna

Let middleware handle MailmanApiErrors

parent 9fd580f7
...@@ -28,19 +28,15 @@ from django.shortcuts import render, redirect ...@@ -28,19 +28,15 @@ from django.shortcuts import render, redirect
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django_mailman3.models import MailDomain from django_mailman3.models import MailDomain
from django.utils.six.moves.urllib.error import HTTPError from django.utils.six.moves.urllib.error import HTTPError
from postorius import utils
from postorius.auth.decorators import superuser_required from postorius.auth.decorators import superuser_required
from postorius.models import Domain, MailmanApiError, Mailman404Error from postorius.models import Domain, Mailman404Error
from postorius.forms import DomainForm from postorius.forms import DomainForm
@login_required @login_required
@superuser_required @superuser_required
def domain_index(request): def domain_index(request):
try: existing_domains = Domain.objects.all()
existing_domains = Domain.objects.all()
except MailmanApiError:
return utils.render_api_error(request)
for domain in existing_domains: for domain in existing_domains:
try: try:
web_host = MailDomain.objects.get(mail_domain=domain.mail_host) web_host = MailDomain.objects.get(mail_domain=domain.mail_host)
...@@ -66,8 +62,6 @@ def domain_new(request): ...@@ -66,8 +62,6 @@ def domain_new(request):
owner=request.user.email) owner=request.user.email)
try: try:
domain.save() domain.save()
except MailmanApiError:
return utils.render_api_error(request)
except HTTPError as e: except HTTPError as e:
form.add_error('mail_host', e.reason) form.add_error('mail_host', e.reason)
else: else:
...@@ -112,8 +106,6 @@ def domain_edit(request, domain): ...@@ -112,8 +106,6 @@ def domain_edit(request, domain):
web_host.save() web_host.save()
try: try:
domain_obj.save() domain_obj.save()
except MailmanApiError:
return utils.render_api_error(request)
except HTTPError as e: except HTTPError as e:
messages.error(request, e) messages.error(request, e)
else: else:
......
This diff is collapsed.
...@@ -32,8 +32,7 @@ from django.utils.translation import gettext as _ ...@@ -32,8 +32,7 @@ from django.utils.translation import gettext as _
from django.views.generic import FormView from django.views.generic import FormView
from django.http import Http404 from django.http import Http404
from postorius import utils from postorius.models import List, MailmanUser
from postorius.models import MailmanApiError, List, MailmanUser
from postorius.forms import ( from postorius.forms import (
UserPreferences, UserPreferencesFormset, ChangeSubscriptionForm) UserPreferences, UserPreferencesFormset, ChangeSubscriptionForm)
from postorius.views.generic import MailmanClientMixin from postorius.views.generic import MailmanClientMixin
...@@ -193,10 +192,7 @@ class UserSubscriptionPreferencesView(UserPreferencesView): ...@@ -193,10 +192,7 @@ class UserSubscriptionPreferencesView(UserPreferencesView):
@login_required @login_required
def user_subscriptions(request): def user_subscriptions(request):
"""Shows the subscriptions of a user.""" """Shows the subscriptions of a user."""
try: mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
except MailmanApiError:
return utils.render_api_error(request)
memberships = [m for m in mm_user.subscriptions if m.role == 'member'] memberships = [m for m in mm_user.subscriptions if m.role == 'member']
return render(request, 'postorius/user/subscriptions.html', return render(request, 'postorius/user/subscriptions.html',
{'memberships': memberships}) {'memberships': memberships})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment