Prepare for 1.3.3 release.
[mailman-postorious.git] / src / postorius / utils.py
blob419f8be23c1a2f6d6ce3d4cc1c5e3483b6a59c9d
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)
9 # any later version.
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
14 # more details.
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/>.
20 import logging
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.
35 """
36 return render(request, 'postorius/errors/generic.html',
37 {'error': _('Mailman REST API not available. Please start Mailman core.')}, # noqa: E501
38 status=503)
41 def render_client_error(request, error):
42 return render(request, 'postorius/errors/generic.html',
43 {'error': str(error)},
44 status=error.code)
47 def get_mailman_client():
48 # easier to patch during unit tests
49 client = Client(
50 '%s/3.1' %
51 settings.MAILMAN_REST_API_URL,
52 settings.MAILMAN_REST_API_USER,
53 settings.MAILMAN_REST_API_PASS)
54 return client
57 def with_empty_choice(choices):
58 """Add an empty Choice for unset values in dropdown."""
59 return [(None, '-----')] + list(choices)
62 LANGUAGES = (
63 ('ar', 'Arabic'),
64 ('ast', 'Asturian'),
65 ('ca', 'Catalan'),
66 ('cs', 'Czech'),
67 ('da', 'Danish'),
68 ('de', 'German'),
69 ('el', 'Greek'),
70 ('es', 'Spanish'),
71 ('et', 'Estonian'),
72 ('eu', 'Euskara'),
73 ('fi', 'Finnish'),
74 ('fr', 'French'),
75 ('gl', 'Galician'),
76 ('he', 'Hebrew'),
77 ('hr', 'Croatian'),
78 ('hu', 'Hungarian'),
79 ('ia', 'Interlingua'),
80 ('it', 'Italian'),
81 ('ja', 'Japanese'),
82 ('ko', 'Korean'),
83 ('lt', 'Lithuanian'),
84 ('nl', 'Dutch'),
85 ('no', 'Norwegian'),
86 ('pl', 'Polish'),
87 ('pt', 'Protuguese'),
88 ('pt_BR', 'Protuguese (Brazil)'),
89 ('ro', 'Romanian'),
90 ('ru', 'Russian'),
91 ('sk', 'Slovak'),
92 ('sl', 'Slovenian'),
93 ('sr', 'Serbian'),
94 ('sv', 'Swedish'),
95 ('tr', 'Turkish'),
96 ('uk', 'Ukrainian'),
97 ('vi', 'Vietnamese'),
98 ('zh_CN', 'Chinese'),
99 ('zh_TW', 'Chinese (Taiwan)'),
100 ('en', 'English (USA)'),