aboutsummaryrefslogtreecommitdiff
path: root/src/django_pgpmailman/views/list.py
diff options
context:
space:
mode:
authorJ08nY2017-08-22 00:58:11 +0200
committerJ08nY2017-08-22 00:58:11 +0200
commit216256f0af673de1d81b10110adf7fa7a5d88f40 (patch)
tree49b7e10713d5a3ad91c7f30caa7d702f7d8f3be0 /src/django_pgpmailman/views/list.py
parentbfc7f14b1df86834abf395fdbf11ab54f076dca6 (diff)
downloaddjango-pgpmailman-216256f0af673de1d81b10110adf7fa7a5d88f40.tar.gz
django-pgpmailman-216256f0af673de1d81b10110adf7fa7a5d88f40.tar.zst
django-pgpmailman-216256f0af673de1d81b10110adf7fa7a5d88f40.zip
Diffstat (limited to 'src/django_pgpmailman/views/list.py')
-rw-r--r--src/django_pgpmailman/views/list.py58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/django_pgpmailman/views/list.py b/src/django_pgpmailman/views/list.py
index f062ff5..f2289b2 100644
--- a/src/django_pgpmailman/views/list.py
+++ b/src/django_pgpmailman/views/list.py
@@ -19,7 +19,7 @@
from __future__ import absolute_import, unicode_literals
from django.contrib import messages
-from django.contrib.auth.decorators import login_required
+from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.files.base import ContentFile
from django.http import HttpResponse, Http404
from django.shortcuts import render
@@ -35,8 +35,8 @@ from django_pgpmailman.decorators import (list_view, list_class_view,
from django_pgpmailman.forms import (ListSignatureSettingsForm,
ListEncryptionSettingsForm,
ListMiscSettingsForm,
- ListKeyManagementForm)
-from django_pgpmailman.plugin import get_plugin
+ ListKeyManagementForm, ListCreateForm)
+from django_pgpmailman.plugin import get_plugin, get_client
def pgp_list_index(request):
@@ -50,6 +50,58 @@ def pgp_list_summary(request, pgp_list):
{'pgp_list': pgp_list})
+class ListCreate(FormView):
+ template_name = 'django_pgpmailman/list/create.html'
+ form_class = ListCreateForm
+ initial = {'advertised': True}
+
+ def get_initial(self):
+ self.initial.update({'list_owner': self.request.user.email})
+ return super(ListCreate, self).get_initial()
+
+ def get_form_kwargs(self):
+ kwargs = super(ListCreate, self).get_form_kwargs()
+ domains = []
+ for domain in get_client().domains:
+ domains.append((domain.mail_host, domain.mail_host))
+ kwargs['domain_choices'] = domains
+ styles = [('pgp-default', 'PGP discussion'),
+ ('pgp-announce', 'PGP announce')]
+ kwargs['style_choices'] = styles
+ return kwargs
+
+ @user_passes_test(lambda u: u.is_superuser)
+ def dispatch(self, request, *args, **kwargs):
+ return super(ListCreate, self).dispatch(request, *args, **kwargs)
+
+ def form_valid(self, form):
+ try:
+ client = get_client()
+ domain = client.get_domain(
+ mail_host=form.cleaned_data['mail_host'])
+
+ mlist = domain.create_list(form.cleaned_data['listname'],
+ style_name=form.cleaned_data[
+ 'list_style'])
+ mlist.add_owner(form.cleaned_data['list_owner'])
+ list_settings = mlist.settings
+ if form.cleaned_data['description']:
+ list_settings['description'] = form.cleaned_data['description']
+ list_settings['advertised'] = form.cleaned_data['advertised']
+ list_settings.save()
+
+ self.mlist = mlist
+ messages.success(self.request, _('List created'))
+ except HTTPError as e:
+ messages.error(self.request, e.msg)
+
+ return super(ListCreate, self).form_valid(form)
+
+ def get_success_url(self):
+ return reverse(self.success_url,
+ kwargs=dict(list_id=self.mlist.list_id))
+
+
class ListKey(View):
which_key = None