Commit 96252aea by Calen Pennington

Merge pull request #358 from MITx/kimth/lms-coderesponse

Kimth/lms coderesponse
parents c79da581 05646fbe
......@@ -800,6 +800,12 @@ class CodeResponse(LoncapaResponse):
'''
Grade student code using an external queueing server, called 'xqueue'
Expects 'xqueue' dict in ModuleSystem with the following keys:
system.xqueue = { 'interface': XqueueInterface object,
'callback_url': Per-StudentModule callback URL where results are posted (string),
'default_queuename': Default queuename to submit request (string)
}
External requests are only submitted for student submission grading
(i.e. and not for getting reference answers)
'''
......@@ -873,15 +879,16 @@ class CodeResponse(LoncapaResponse):
'edX_cmd': 'get_score',
'edX_tests': self.tests,
'processor': self.code,
'edX_student_response': unicode(submission), # unicode on File object returns its filename
}
# Submit request
if hasattr(submission, 'read'): # Test for whether submission is a file
if is_file(submission):
contents.update({'edX_student_response': submission.name})
(error, msg) = qinterface.send_to_queue(header=xheader,
body=json.dumps(contents),
file_to_upload=submission)
else:
contents.update({'edX_student_response': submission})
(error, msg) = qinterface.send_to_queue(header=xheader,
body=json.dumps(contents))
......
......@@ -39,13 +39,13 @@ def convert_files_to_filenames(answers):
'''
new_answers = dict()
for answer_id in answers.keys():
if is_uploaded_file(answers[answer_id]):
if is_file(answers[answer_id]):
new_answers[answer_id] = answers[answer_id].name
else:
new_answers[answer_id] = answers[answer_id]
return new_answers
def is_uploaded_file(file_to_test):
def is_file(file_to_test):
'''
Duck typing to check if 'file_to_test' is a File object
'''
......
......@@ -32,7 +32,7 @@ i4xs = ModuleSystem(
user=Mock(),
filestore=fs.osfs.OSFS(os.path.dirname(os.path.realpath(__file__))),
debug=True,
xqueue={'default_queuename': 'testqueue'},
xqueue={'interface':None, 'callback_url':'/', 'default_queuename': 'testqueue'},
is_staff=False
)
......
......@@ -679,10 +679,7 @@ class ModuleSystem(object):
TODO (vshnayder): this will need to change once we have real user roles.
'''
self.ajax_url = ajax_url
if xqueue is None:
self.xqueue = {'interface':None, 'callback_url':'/', 'default_queuename':'null'}
else:
self.xqueue = xqueue
self.xqueue = xqueue
self.track_function = track_function
self.filestore = filestore
self.get_module = get_module
......
......@@ -252,7 +252,6 @@ def get_shared_instance_module(user, module, student_module_cache):
else:
return None
@csrf_exempt
def xqueue_callback(request, userid, id, dispatch):
'''
......@@ -270,13 +269,12 @@ def xqueue_callback(request, userid, id, dispatch):
user = User.objects.get(id=userid)
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(user, modulestore().get_item(id))
instance = get_module(request.user, request, id, student_module_cache)
instance_module = get_instance_module(request.user, instance, student_module_cache)
instance = get_module(user, request, id, student_module_cache)
instance_module = get_instance_module(user, instance, student_module_cache)
if instance_module is None:
log.debug("Couldn't find module '%s' for user '%s'",
id, request.user)
id, user)
raise Http404
oldgrade = instance_module.grade
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment