Mercurial > public > sg101
comparison gpp/forums/views/subscriptions.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 | 9d3bd7304050 |
children |
comparison
equal
deleted
inserted
replaced
521:dd14ab08a9c4 | 522:82b97697312e |
---|---|
16 import forums.permissions as perms | 16 import forums.permissions as perms |
17 from core.functions import send_mail | 17 from core.functions import send_mail |
18 from core.paginator import DiggPaginator | 18 from core.paginator import DiggPaginator |
19 | 19 |
20 | 20 |
21 def notify_topic_subscribers(post): | 21 def notify_topic_subscribers(post, defer=True): |
22 """ | 22 """ |
23 The argument post is a newly created post. Send out an email | 23 The argument post is a newly created post. Send out an email |
24 notification to all subscribers of the post's parent Topic. | 24 notification to all subscribers of the post's parent Topic. |
25 | |
26 The defer flag is passed to core.functions.send_mail. If True, the mail is | |
27 sent on a Celery task. If False, the mail is sent on the caller's thread. | |
25 """ | 28 """ |
26 #TODO: consider moving this function of the HTTP request/response cycle. | |
27 | |
28 topic = post.topic | 29 topic = post.topic |
29 recipients = topic.subscribers.exclude(id=post.user.id).values_list( | 30 recipients = topic.subscribers.exclude(id=post.user.id).values_list( |
30 'email', flat=True) | 31 'email', flat=True) |
31 | 32 |
32 if recipients: | 33 if recipients: |
41 'message': post.body, | 42 'message': post.body, |
42 'post_url': post_url, | 43 'post_url': post_url, |
43 'unsubscribe_url': unsubscribe_url, | 44 'unsubscribe_url': unsubscribe_url, |
44 }) | 45 }) |
45 for recipient in recipients: | 46 for recipient in recipients: |
46 send_mail(subject, msg, settings.DEFAULT_FROM_EMAIL, [recipient]) | 47 send_mail(subject, msg, settings.DEFAULT_FROM_EMAIL, [recipient], |
48 defer=defer) | |
47 | 49 |
48 | 50 |
49 @login_required | 51 @login_required |
50 @require_POST | 52 @require_POST |
51 def subscribe_topic(request, topic_id): | 53 def subscribe_topic(request, topic_id): |