Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
521:dd14ab08a9c4 | 522:82b97697312e |
---|---|
3 import re | 3 import re |
4 import logging | 4 import logging |
5 | 5 |
6 from django.contrib.sites.models import Site | 6 from django.contrib.sites.models import Site |
7 from django.conf import settings | 7 from django.conf import settings |
8 import django.core.mail | |
8 | 9 |
9 import core.tasks | 10 import core.tasks |
10 | 11 |
11 | 12 |
12 def send_mail(subject, message, from_email, recipient_list, **kwargs): | 13 def send_mail(subject, message, from_email, recipient_list, defer=True, **kwargs): |
13 """ | 14 """ |
14 The main send email function. Use this function to send email from the | 15 The main send email function. Use this function to send email from the |
15 site. All applications should use this function instead of calling | 16 site. All applications should use this function instead of calling |
16 Django's directly. | 17 Django's directly. |
17 If settings.GPP_SEND_EMAIL is true, the email will be sent to a Celery task | 18 If defer is True, the email will be sent to a Celery task to actually send |
18 to actually send the email. Otherwise it is dropped. In any event, the | 19 the email. Otherwise it is sent on the caller's thread. In any event, the |
19 email will be logged at the DEBUG level. | 20 email will be logged at the DEBUG level. |
20 | 21 |
21 """ | 22 """ |
22 # Guard against empty email addresses | 23 # Guard against empty email addresses |
23 recipient_list = [dest for dest in recipient_list if dest] | 24 recipient_list = [dest for dest in recipient_list if dest] |
26 return | 27 return |
27 | 28 |
28 logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s', | 29 logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s', |
29 from_email, str(recipient_list), subject, message) | 30 from_email, str(recipient_list), subject, message) |
30 | 31 |
31 if settings.GPP_SEND_EMAIL: | 32 if defer: |
32 core.tasks.send_mail.delay(subject, message, from_email, recipient_list, | 33 core.tasks.send_mail.delay(subject, message, from_email, recipient_list, |
34 **kwargs) | |
35 else: | |
36 django.core.mail.send_mail(subject, message, from_email, recipient_list, | |
33 **kwargs) | 37 **kwargs) |
34 | 38 |
35 | 39 |
36 def email_admins(subject, message): | 40 def email_admins(subject, message): |
37 """Emails the site admins. Goes through the site send_mail function.""" | 41 """Emails the site admins. Goes through the site send_mail function.""" |