Don't try to send notification email if assigned_to is blank

- Supports unassigned tasks
This commit is contained in:
Scot Hacker 2018-02-11 23:01:37 -08:00
parent 5cbfc554ee
commit 91c0075ccf
2 changed files with 14 additions and 15 deletions

View file

@ -10,9 +10,6 @@ Note: {{ task.note }}
{% endautoescape %} {% endautoescape %}
{% endif %} {% endif %}
Task details/comments: Task details/comments:
http://{{ site }}{% url 'todo:task_detail' task.id %} http://{{ site }}{% url 'todo:task_detail' task.id %}

View file

@ -29,15 +29,17 @@ def toggle_deleted(request, deleted_items):
def send_notify_mail(request, new_task): def send_notify_mail(request, new_task):
# Send email # Send email to assignee when task is assigned to someone else.
current_site = Site.objects.get_current() # Unassigned tasks should not try to notify.
email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task}) if new_task.assigned_to:
email_body = render_to_string( current_site = Site.objects.get_current()
"todo/email/assigned_body.txt", email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task})
{'task': new_task, 'site': current_site, }) email_body = render_to_string(
try: "todo/email/assigned_body.txt",
send_mail( {'task': new_task, 'site': current_site, })
email_subject, email_body, new_task.created_by.email, try:
[new_task.assigned_to.email], fail_silently=False) send_mail(
except ConnectionRefusedError: email_subject, email_body, new_task.created_by.email,
messages.error(request, "Task saved but mail not sent. Contact your administrator.") [new_task.assigned_to.email], fail_silently=False)
except ConnectionRefusedError:
messages.error(request, "Task saved but mail not sent. Contact your administrator.")