Mercurial > public > sg101
diff gpp/core/functions.py @ 522:82b97697312e
Created Celery tasks to process new posts and topics. Keep the updated topic set in Redis.
This is for tickets #194, #237, #239.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 18 Dec 2011 23:46:52 +0000 |
parents | 9e7ae8462f3f |
children | 4b9970ad0edb |
line wrap: on
line diff
--- a/gpp/core/functions.py Sat Dec 17 23:43:00 2011 +0000 +++ b/gpp/core/functions.py Sun Dec 18 23:46:52 2011 +0000 @@ -5,17 +5,18 @@ from django.contrib.sites.models import Site from django.conf import settings +import django.core.mail import core.tasks -def send_mail(subject, message, from_email, recipient_list, **kwargs): +def send_mail(subject, message, from_email, recipient_list, defer=True, **kwargs): """ The main send email function. Use this function to send email from the site. All applications should use this function instead of calling Django's directly. - If settings.GPP_SEND_EMAIL is true, the email will be sent to a Celery task - to actually send the email. Otherwise it is dropped. In any event, the + If defer is True, the email will be sent to a Celery task to actually send + the email. Otherwise it is sent on the caller's thread. In any event, the email will be logged at the DEBUG level. """ @@ -28,9 +29,12 @@ logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s', from_email, str(recipient_list), subject, message) - if settings.GPP_SEND_EMAIL: + if defer: core.tasks.send_mail.delay(subject, message, from_email, recipient_list, **kwargs) + else: + django.core.mail.send_mail(subject, message, from_email, recipient_list, + **kwargs) def email_admins(subject, message):