Add handling of mailinglist subscription
authorMagnus Hagander <magnus@hagander.net>
Mon, 28 Dec 2009 17:57:01 +0000 (18:57 +0100)
committerMagnus Hagander <magnus@hagander.net>
Mon, 28 Dec 2009 17:57:01 +0000 (18:57 +0100)
pgweb/lists/forms.py [new file with mode: 0644]
pgweb/lists/views.py
pgweb/urls.py
templates/lists/subscribed.html [new file with mode: 0644]

diff --git a/pgweb/lists/forms.py b/pgweb/lists/forms.py
new file mode 100644 (file)
index 0000000..7648b85
--- /dev/null
@@ -0,0 +1,11 @@
+from django import forms
+
+from models import MailingList
+
+class SubscribeForm(forms.Form):
+       email = forms.EmailField(max_length=100,required=True,label="Email address")
+       action = forms.ChoiceField(required=True, choices=(('subscribe','Subscribe'),('unsubscribe','Unsubscribe')))
+       receive = forms.BooleanField(required=False, label="Receive mail", initial=True)
+       digest = forms.BooleanField(required=False, label="Digest only")
+       lists = forms.ModelChoiceField(required=True, queryset=MailingList.objects.filter(active=True), label="Mailinglist")
+
index eee529b360a479a788c5387070e4ee54bebf5116..ae97d8024e4a069e2ccd97d500cd32600362071f 100644 (file)
@@ -2,10 +2,15 @@ from django.shortcuts import render_to_response, get_object_or_404
 from django.http import HttpResponse, Http404, HttpResponseRedirect
 from django.template import TemplateDoesNotExist, loader, Context
 from django.contrib.auth.decorators import login_required
+from django.conf import settings
+
+from email.mime.text import MIMEText
 
 from pgweb.util.contexts import NavContext
+from pgweb.util.misc import sendmail
 
 from models import MailingList, MailingListGroup
+from forms import SubscribeForm
 
 def root(request):
        lists = MailingList.objects.all().order_by('group__sortkey', 'listname')
@@ -14,3 +19,35 @@ def root(request):
                'lists': lists,
        }, NavContext(request, 'community'))
 
+def subscribe(request):
+       if request.POST:
+               form = SubscribeForm(request.POST)
+               if form.is_valid():
+                       mailtxt = ""
+                       if form.cleaned_data['action'] == 'subscribe':
+                               mailtxt += "subscribe %s\n" % form.cleaned_data['lists']
+                               if not form.cleaned_data['receive']:
+                                       mailtxt += "set nomail\n"
+                               if form.cleaned_data['digest']:
+                                       mailtxt += "set digest\n"
+                       else:
+                               mailtxt += "unsubscribe %s\n" % form.cleaned_data['lists']
+                       msg = MIMEText(mailtxt, _charset='utf-8')
+                       msg['Subject'] = ''
+                       msg['To'] = settings.LISTSERVER_EMAIL
+                       msg['From'] = form.cleaned_data['email']
+                       sendmail(msg)
+                       return render_to_response('lists/subscribed.html', {
+                       }, NavContext(request, "community"))
+       else:
+               # GET, so render up the form
+               form = SubscribeForm()
+
+       return render_to_response('base/form.html', {
+               'form': form,
+               'form_intro': """
+Please do not subscribe to mailing lists using e-mail accounts protected by
+mail-back anti-spam systems. These are extremely annoying to the list maintainers
+and other members, and you may be automatically unsubscribed."""
+       }, NavContext(request, "community"))
+
index e0b630cd09ddb744831825aa492c90744e63ad6b..67f58ffb6bb9005484b2b86c3f794adc8162e640 100644 (file)
@@ -37,6 +37,7 @@ urlpatterns = patterns('',
     (r'^community/$', 'core.views.community'),
     (r'^community/contributors/$', 'contributors.views.completelist'),
     (r'^community/lists/$', 'lists.views.root'),
+    (r'^community/lists/subscribe/$', 'lists.views.subscribe'),
     (r'^community/survey/vote/(\d+)/$', 'survey.views.vote'),
     (r'^community/survey[/\.](\d+)(-.*)?/$', 'survey.views.results'),
 
diff --git a/templates/lists/subscribed.html b/templates/lists/subscribed.html
new file mode 100644 (file)
index 0000000..37f38b2
--- /dev/null
@@ -0,0 +1,11 @@
+{%extends "base/page.html"%}
+{%block title%}Subscribed{%endblock%}
+{%block contents%}
+
+<h1>Subscribed</h1>
+
+<p>Your subscription request has been sent to the mailinglist server. You
+will receive a confirmation email shortly.</p>
+
+{%endblock%}
+