def send_reply_notifications(content_id):
"""Super simple reply notification to content local participants.
Until proper notifications is supported, just pop out an email.
"""
if settings.DEBUG:
return
try:
content = Content.objects.get(id=content_id, content_type=ContentType.REPLY)
except Content.DoesNotExist:
logger.warning("No reply content found with id %s", content_id)
return
root_content = content.root
exclude_user = content.author.user if content.local else None
participants = get_root_content_participants(root_content, exclude_user=exclude_user)
if not participants:
return
subject = _("New reply to: %s" % root_content.short_text_inline)
# TODO use fragment url to reply directly when available
content_url = "%s%s" % (settings.SOCIALHOME_URL, root_content.get_absolute_url())
context = get_common_context()
context.update({
"subject": subject, "actor_name": content.author.name_or_handle,
"actor_url": "%s%s" % (settings.SOCIALHOME_URL, content.author.get_absolute_url()),
"reply_text": content.text, "reply_rendered": content.rendered, "reply_url": content_url,
})
for participant in participants:
context["name"] = participant.profile.name_or_handle
logger.info("send_reply_notifications - Sending mail to %s", participant.email)
send_mail(
"%s%s" % (settings.EMAIL_SUBJECT_PREFIX, subject),
render_to_string("notifications/reply.txt", context=context),
settings.DEFAULT_FROM_EMAIL,
[participant.email],
fail_silently=False,
html_message=render_to_string("notifications/reply.html", context=context),
)
评论列表
文章目录