diff options
Diffstat (limited to 'src/django_pgpmailman/plugin.py')
| -rw-r--r-- | src/django_pgpmailman/plugin.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/django_pgpmailman/plugin.py b/src/django_pgpmailman/plugin.py new file mode 100644 index 0000000..77ed5c8 --- /dev/null +++ b/src/django_pgpmailman/plugin.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2017 Jan Jancar +# +# This file is a part of the Django Mailman PGP plugin. +# +# This program 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. +# +# This program 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 +# this program. If not, see <http://www.gnu.org/licenses/>. +from operator import itemgetter + +from django.conf import settings +from django_mailman3.lib.mailman import get_mailman_client +from mailmanclient._client import Plugin + +from django_pgpmailman.models import PGPMailingList + + +class PGPPlugin(Plugin): + def __init__(self, base_plugin): + super(PGPPlugin, self).__init__(base_plugin.connection, + base_plugin.name, + base_plugin.rest_data) + self._base_plugin = base_plugin + + @property + def lists(self): + response, content = self.call('lists') + if 'entries' not in content: + return [] + return [PGPMailingList(self._connection, entry['self_link'], entry) for + entry in sorted(content['entries'], key=itemgetter('list_id'))] + + def get_list(self, list_identifier): + response, content = self.call('lists/{}'.format(list_identifier)) + return PGPMailingList(self._connection, content['self_link', content]) + + +def get_pgp_plugin(): + return PGPPlugin( + get_mailman_client().get_plugin(settings.MAILMAN_PGP_PLUGIN_NAME)) |
