From 1b6123294d2da8c67cded26616f0db39768e81b6 Mon Sep 17 00:00:00 2001
From: bmedx <bmesick@edx.org>
Date: Thu, 2 Mar 2017 15:29:54 -0500
Subject: [PATCH] Fixes to celery queuing and text

---
 cms/djangoapps/cms_user_tasks/signals.py          | 7 ++++++-
 cms/djangoapps/cms_user_tasks/tests.py            | 4 ++--
 cms/templates/emails/user_task_complete_email.txt | 4 ++--
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/cms/djangoapps/cms_user_tasks/signals.py b/cms/djangoapps/cms_user_tasks/signals.py
index cf943b7a1c8..00d2ccda726 100644
--- a/cms/djangoapps/cms_user_tasks/signals.py
+++ b/cms/djangoapps/cms_user_tasks/signals.py
@@ -1,6 +1,7 @@
 """
 Receivers of signals sent from django-user-tasks
 """
+import logging
 from urlparse import urljoin
 
 from django.core.urlresolvers import reverse
@@ -42,4 +43,8 @@ def user_task_stopped_handler(sender, **kwargs):  # pylint: disable=unused-argum
                 reverse('usertaskstatus-detail', args=[status.uuid])
             )
 
-        send_task_complete_email.delay(status.name, status.state_text, status.user.email, detail_url)
+        try:
+            # Need to str state_text here because it is a proxy object and won't serialize correctly
+            send_task_complete_email.delay(status.name.lower(), str(status.state_text), status.user.email, detail_url)
+        except Exception as e:  # pylint: disable=broad-except
+            logging.exception("Unable to queue send_task_complete_email")
diff --git a/cms/djangoapps/cms_user_tasks/tests.py b/cms/djangoapps/cms_user_tasks/tests.py
index 3677a278525..3e31dd121de 100644
--- a/cms/djangoapps/cms_user_tasks/tests.py
+++ b/cms/djangoapps/cms_user_tasks/tests.py
@@ -145,7 +145,7 @@ class TestUserTaskStopped(APITestCase):
             platform_name=settings.PLATFORM_NAME, studio_name=settings.STUDIO_NAME
         )
         body_fragments = [
-            "Your {task_name} task has completed with the status".format(task_name=self.status.name),
+            "Your {task_name} task has completed with the status".format(task_name=self.status.name.lower()),
             "https://test.edx.org/",
             reverse('usertaskstatus-detail', args=[self.status.uuid])
         ]
@@ -182,7 +182,7 @@ class TestUserTaskStopped(APITestCase):
             platform_name=settings.PLATFORM_NAME, studio_name=settings.STUDIO_NAME
         )
         fragments = [
-            "Your {task_name} task has completed with the status".format(task_name=self.status.name),
+            "Your {task_name} task has completed with the status".format(task_name=self.status.name.lower()),
             "Sign in to view the details of your task or download any files created."
         ]
 
diff --git a/cms/templates/emails/user_task_complete_email.txt b/cms/templates/emails/user_task_complete_email.txt
index c3e9c33b910..05b49cc8b82 100644
--- a/cms/templates/emails/user_task_complete_email.txt
+++ b/cms/templates/emails/user_task_complete_email.txt
@@ -2,10 +2,10 @@
 
 % if detail_url:
 
-${_("Your {task_name} task has completed with the status {task_status}. Use this URL to view task details or download any files created: {detail_url}").format(task_name=task_name, task_status=task_status, detail_url=detail_url)}
+${_("Your {task_name} task has completed with the status '{task_status}'. Use this URL to view task details or download any files created: {detail_url}").format(task_name=task_name, task_status=task_status, detail_url=detail_url)}
 
 % else:
 
-${_("Your {task_name} task has completed with the status {task_status}. Sign in to view the details of your task or download any files created.").format(task_name=task_name, task_status=task_status)}
+${_("Your {task_name} task has completed with the status '{task_status}'. Sign in to view the details of your task or download any files created.").format(task_name=task_name, task_status=task_status)}
 
 % endif
-- 
GitLab