diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-05-28 06:22:56 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-05-28 06:22:56 -0400 |
commit | 1815e7a2f5b01652a19caeddd2ab0cfb63fe9139 (patch) | |
tree | 1a4903ab0d384913da65404a4b05017ef185aa29 /askbot/tasks.py | |
parent | 12382d0eecbd8228e3dc47c2a419371b22507927 (diff) | |
download | askbot-1815e7a2f5b01652a19caeddd2ab0cfb63fe9139.tar.gz askbot-1815e7a2f5b01652a19caeddd2ab0cfb63fe9139.tar.bz2 askbot-1815e7a2f5b01652a19caeddd2ab0cfb63fe9139.zip |
hopefully fixed bugs with the approval notification messages
Diffstat (limited to 'askbot/tasks.py')
-rw-r--r-- | askbot/tasks.py | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/askbot/tasks.py b/askbot/tasks.py index 447b6b78..71719ef3 100644 --- a/askbot/tasks.py +++ b/askbot/tasks.py @@ -21,11 +21,14 @@ import sys import traceback from django.contrib.contenttypes.models import ContentType +from django.template import Context +from django.utils.translation import ugettext as _ from celery.decorators import task from askbot.conf import settings as askbot_settings -from askbot.models import Activity, Post, Thread, User +from askbot import const +from askbot import mail +from askbot.models import Activity, Post, Thread, User, ReplyAddress from askbot.models import send_instant_notifications_about_activity_in_post -from askbot.models import notify_author_about_approved_post from askbot.models.badges import award_badges_signal # TODO: Make exceptions raised inside record_post_update_celery_task() ... @@ -33,8 +36,58 @@ from askbot.models.badges import award_badges_signal # (i.e. if Celery tasks are not deferred but executed straight away) @task(ignore_result = True) -def notify_author_about_approved_post_celery_task(post): - notify_author_about_approved_post(post) +def notify_author_of_published_revision_celery_task(revision): + #for answerable email only for now, because + #we don't yet have the template for the read-only notification + if askbot_settings.REPLY_BY_EMAIL: + #generate two reply codes (one for edit and one for addition) + #to format an answerable email or not answerable email + reply_options = { + 'user': revision.author, + 'post': revision.post, + 'reply_action': 'append_content' + } + append_content_address = ReplyAddress.objects.create_new( + **reply_options + ).as_email_address() + reply_options['reply_action'] = 'replace_content' + replace_content_address = ReplyAddress.objects.create_new( + **reply_options + ).as_email_address() + + #populate template context variables + reply_code = append_content_address + ',' + replace_content_address + if revision.post.post_type == 'question': + mailto_link_subject = revision.post.thread.title + else: + mailto_link_subject = _('An edit for my answer') + #todo: possibly add more mailto thread headers to organize messages + + prompt = _('To add to your post EDIT ABOVE THIS LINE') + reply_separator_line = const.SIMPLE_REPLY_SEPARATOR_TEMPLATE % prompt + data = { + 'site_name': askbot_settings.APP_SHORT_NAME, + 'post': revision.post, + 'replace_content_address': replace_content_address, + 'reply_separator_line': reply_separator_line, + 'mailto_link_subject': mailto_link_subject, + 'reply_code': reply_code + } + + #load the template + from askbot.skins.loaders import get_template + template = get_template('email/notify_author_about_approved_post.html') + #todo: possibly add headers to organize messages in threads + headers = {'Reply-To': append_content_address} + #send the message + mail.send_mail( + subject_line = _('Your post at %(site_name)s was approved') % data, + body_text = template.render(Context(data)), + recipient_list = [revision.author.email,], + related_object = revision, + activity_type = const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT, + headers = headers + ) @task(ignore_result = True) def record_post_update_celery_task( |