Files
postgres-web/pgweb/lists/views.py
Magnus Hagander 8f0b7e6b50 Switch email sending go through a queue table in the database
Import the code from the PostgreSQL Europe website to handle this, since it's
well proven by now.

Any points that send email now just write them to the database using the
functions in queuedmail.util. This means we can now submit notification
emails and such things within transactions and have them properly roll bcak
if something goes wrong (so no more incorrect notifications when there is
a database error).

These emails are picked up by a cronjob that runs frequently (typically
once per minute or once every 2 minutes) that submits them to the local
mailserver. By doing it out of line, this gives us a much better way of
dealing with cases where mail delivery is really slow.

The submission from the cronjob is now done with smtp to localhost instead
of opening a pipe to the sendmail command - though this should have no
major effects on anything.

This also removes the setting SUPPRESS_NOTIFICATIONS, as no notifications
are actually ever sent unless the cronjob is run. On development systems
they will just go into the queuedmail table, and can be deleted from there.
2014-01-11 12:33:06 +01:00

67 lines
1.9 KiB
Python

from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
import simplejson as json
from pgweb.util.contexts import NavContext
from pgweb.mailqueue.util import send_simple_mail
from models import MailingList, MailingListGroup
from forms import SubscribeForm
@csrf_exempt
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']
send_simple_mail(form.cleaned_data['email'],
settings.LISTSERVER_EMAIL,
'',
mailtxt)
return render_to_response('lists/subscribed.html', {
}, NavContext(request, "community"))
else:
# GET, so render up the form
form = SubscribeForm()
return render_to_response('lists/subscribe_form.html', {
'form': form,
'operation': 'Subscribe',
'jquery': True,
'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"))
def listinfo(request):
resp = HttpResponse(mimetype='application/json')
groupdata = [ {
'id': g.id,
'name': g.groupname,
'sort': g.sortkey,
} for g in MailingListGroup.objects.all()]
listdata = [ {
'id': l.id,
'name': l.listname,
'groupid': l.group_id,
'active': l.active,
'shortdesc': l.shortdesc,
'description': l.description,
} for l in MailingList.objects.all()]
json.dump({'groups': groupdata, 'lists': listdata}, resp)
return resp