2016-08-02 08:32:29 +00:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.core.mail import send_mail
|
2018-02-03 08:09:23 +00:00
|
|
|
from django.template.loader import render_to_string
|
2016-08-02 08:32:29 +00:00
|
|
|
|
2018-04-08 07:49:01 +00:00
|
|
|
from todo.models import Comment
|
2018-03-28 06:17:01 +00:00
|
|
|
|
2016-08-02 08:32:29 +00:00
|
|
|
|
2018-03-28 06:17:01 +00:00
|
|
|
def send_notify_mail(new_task):
|
2018-03-14 07:22:37 +00:00
|
|
|
# Send email to assignee if task is assigned to someone other than submittor.
|
2018-02-12 07:01:37 +00:00
|
|
|
# Unassigned tasks should not try to notify.
|
2018-03-14 07:22:37 +00:00
|
|
|
|
2018-03-28 07:07:29 +00:00
|
|
|
if not new_task.assigned_to == new_task.created_by:
|
2018-02-12 07:01:37 +00:00
|
|
|
current_site = Site.objects.get_current()
|
|
|
|
email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task})
|
|
|
|
email_body = render_to_string(
|
|
|
|
"todo/email/assigned_body.txt",
|
|
|
|
{'task': new_task, 'site': current_site, })
|
2018-03-14 07:22:37 +00:00
|
|
|
|
|
|
|
send_mail(
|
|
|
|
email_subject, email_body, new_task.created_by.email,
|
|
|
|
[new_task.assigned_to.email], fail_silently=False)
|
|
|
|
|
|
|
|
|
2018-03-28 06:17:01 +00:00
|
|
|
def send_email_to_thread_participants(task, msg_body, user):
|
2018-03-14 07:22:37 +00:00
|
|
|
# Notify all previous commentors on a Task about a new comment.
|
|
|
|
|
|
|
|
current_site = Site.objects.get_current()
|
|
|
|
email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': task})
|
|
|
|
email_body = render_to_string(
|
|
|
|
"todo/email/newcomment_body.txt",
|
2018-03-28 06:17:01 +00:00
|
|
|
{'task': task, 'body': msg_body, 'site': current_site, 'user': user}
|
2018-03-14 07:22:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Get list of all thread participants - everyone who has commented, plus task creator.
|
|
|
|
commenters = Comment.objects.filter(task=task)
|
|
|
|
recip_list = [ca.author.email for ca in commenters]
|
|
|
|
recip_list.append(task.created_by.email)
|
|
|
|
recip_list = list(set(recip_list)) # Eliminate duplicates
|
|
|
|
|
|
|
|
send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)
|