1 # -*- coding: utf-8 -*-
2 # Copyright (C) 1998-2019 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
22 from django
.conf
import settings
23 from django
.shortcuts
import render
24 from django
.utils
.translation
import gettext
as _
26 from mailmanclient
import Client
29 logger
= logging
.getLogger(__name__
)
32 def render_api_error(request
):
33 """Renders an error template.
34 Use if MailmanApiError is catched.
36 return render(request
, 'postorius/errors/generic.html',
37 {'error': _('Mailman REST API not available. Please start Mailman core.')}, # noqa: E501
41 def render_client_error(request
, error
):
42 return render(request
, 'postorius/errors/generic.html',
43 {'error': str(error
)},
47 def get_mailman_client():
48 # easier to patch during unit tests
51 settings
.MAILMAN_REST_API_URL
,
52 settings
.MAILMAN_REST_API_USER
,
53 settings
.MAILMAN_REST_API_PASS
)
57 def with_empty_choice(choices
):
58 """Add an empty Choice for unset values in dropdown."""
59 return [(None, '-----')] + list(choices
)
79 ('ia', 'Interlingua'),
88 ('pt_BR', 'Protuguese (Brazil)'),
99 ('zh_TW', 'Chinese (Taiwan)'),
100 ('en', 'English (USA)'),