From fd206a412822608ceee7f83b2fc95be29b6ca4d0 Mon Sep 17 00:00:00 2001
From: Brian Wilson
Date: Tue, 18 Jun 2013 15:07:15 -0400
Subject: [PATCH] Make sure InstructorTask is committed.
---
common/lib/xmodule/xmodule/tests/test_capa_module.py | 4 ++--
lms/djangoapps/instructor_task/models.py | 11 ++++++-----
lms/djangoapps/instructor_task/tests/test_api.py | 4 ++--
lms/templates/courseware/instructor_dashboard.html | 8 ++++----
4 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py
index e738d8e031..deb6f13e20 100644
--- a/common/lib/xmodule/xmodule/tests/test_capa_module.py
+++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py
@@ -658,11 +658,11 @@ class CapaModuleTest(unittest.TestCase):
# Simulate answering a problem that raises the exception
with patch('capa.capa_problem.LoncapaProblem.rescore_existing_answers') as mock_rescore:
- mock_rescore.side_effect = exception_class(u'test error u\03a9')
+ mock_rescore.side_effect = exception_class(u'test error \u03a9')
result = module.rescore_problem()
# Expect an AJAX alert message in 'success'
- expected_msg = u'Error: test error u\03a9'
+ expected_msg = u'Error: test error \u03a9'
self.assertEqual(result['success'], expected_msg)
# Expect that the number of attempts is NOT incremented
diff --git a/lms/djangoapps/instructor_task/models.py b/lms/djangoapps/instructor_task/models.py
index f95897859e..f1ebf814fa 100644
--- a/lms/djangoapps/instructor_task/models.py
+++ b/lms/djangoapps/instructor_task/models.py
@@ -91,7 +91,7 @@ class InstructorTask(models.Model):
task_input=json_task_input,
task_state=QUEUING,
requester=requester)
- instructor_task.save()
+ instructor_task.save_now()
return instructor_task
@@ -125,6 +125,7 @@ class InstructorTask(models.Model):
Truncation is indicated by adding "..." to the end of the value.
"""
+ tag = '...'
task_progress = {'exception': type(exception).__name__, 'message': str(exception.message)}
if traceback_string is not None:
# truncate any traceback that goes into the InstructorTask model:
@@ -135,17 +136,17 @@ class InstructorTask(models.Model):
too_long = len(json_output) - 1023
if too_long > 0:
if traceback_string is not None:
- if too_long >= len(traceback_string) - len('...'):
+ if too_long >= len(traceback_string) - len(tag):
# remove the traceback entry entirely (so no key or value)
del task_progress['traceback']
too_long -= (len(traceback_string) + len('traceback'))
else:
# truncate the traceback:
- task_progress['traceback'] = traceback_string[:-(too_long + 3)] + "..."
- too_long = -1
+ task_progress['traceback'] = traceback_string[:-(too_long + len(tag))] + tag
+ too_long = 0
if too_long > 0:
# we need to shorten the message:
- task_progress['message'] = task_progress['message'][:-(too_long + 3)] + "..."
+ task_progress['message'] = task_progress['message'][:-(too_long + len(tag))] + tag
json_output = json.dumps(task_progress)
return json_output
diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py
index 6ab710eef9..841fdca8a0 100644
--- a/lms/djangoapps/instructor_task/tests/test_api.py
+++ b/lms/djangoapps/instructor_task/tests/test_api.py
@@ -109,10 +109,10 @@ class InstructorTaskSubmitTest(InstructorTaskModuleTestCase):
location = InstructorTaskModuleTestCase.problem_location(problem_url_name)
if student is not None:
instructor_task = task_function(self.create_task_request(self.instructor),
- self.course.id, location, student)
+ self.course.id, location, student)
else:
instructor_task = task_function(self.create_task_request(self.instructor),
- self.course.id, location)
+ self.course.id, location)
# test resubmitting, by updating the existing record:
instructor_task = InstructorTask.objects.get(id=instructor_task.id)
diff --git a/lms/templates/courseware/instructor_dashboard.html b/lms/templates/courseware/instructor_dashboard.html
index 19c6cef70b..ef1eb174fc 100644
--- a/lms/templates/courseware/instructor_dashboard.html
+++ b/lms/templates/courseware/instructor_dashboard.html
@@ -205,8 +205,8 @@ function goto( mode)
You may use just the "urlname" if a problem, or "modulename/urlname" if not.
- (For example, if the location is i4x://university/course/problem/problemname,
- then just provide the problemname.
+ (For example, if the location is i4x://university/course/problem/problemname,
+ then just provide the problemname.
If the location is i4x://university/course/notaproblem/someothername, then
provide notaproblem/someothername.)
@@ -241,8 +241,8 @@ function goto( mode)
You may use just the "urlname" if a problem, or "modulename/urlname" if not.
- (For example, if the location is i4x://university/course/problem/problemname,
- then just provide the problemname.
+ (For example, if the location is i4x://university/course/problem/problemname,
+ then just provide the problemname.
If the location is i4x://university/course/notaproblem/someothername, then
provide notaproblem/someothername.)