Commit 41e7d72e by kimth

Xqueue interface is embedded in ModuleSystem

parent 7cc502c8
......@@ -29,7 +29,6 @@ import xqueue_interface
log = logging.getLogger('mitx.' + __name__)
qinterface = xqueue_interface.XqueueInterface()
#-----------------------------------------------------------------------------
# Exceptions
......@@ -811,7 +810,7 @@ class CodeResponse(LoncapaResponse):
def setup_response(self):
xml = self.xml
self.queue_name = xml.get('queuename', self.system.xqueue_default_queuename)
self.queue_name = xml.get('queuename', self.system.xqueue['default_queuename'])
answer = xml.find('answer')
if answer is not None:
......@@ -859,10 +858,11 @@ class CodeResponse(LoncapaResponse):
# Prepare xqueue request
#------------------------------------------------------------
qinterface = self.system.xqueue['interface']
# Generate header
queuekey = xqueue_interface.make_hashkey(self.system.seed)
xheader = xqueue_interface.make_xheader(lms_callback_url=self.system.xqueue_callback_url,
queuekey = xqueue_interface.make_hashkey(str(self.system.seed)+self.answer_id)
xheader = xqueue_interface.make_xheader(lms_callback_url=self.system.xqueue['callback_url'],
lms_key=queuekey,
queue_name=self.queue_name)
......
......@@ -112,3 +112,5 @@ class XqueueInterface:
return (1, 'cannot connect to server')
return parse_xreply(r.text)
qinterface = XqueueInterface()
......@@ -587,7 +587,7 @@ class ModuleSystem(object):
def __init__(self, ajax_url, track_function,
get_module, render_template, replace_urls,
user=None, filestore=None, debug=False,
xqueue_callback_url=None, xqueue_default_queuename="null"):
xqueue=None):
'''
Create a closure around the system environment.
......@@ -615,8 +615,7 @@ class ModuleSystem(object):
ajax results.
'''
self.ajax_url = ajax_url
self.xqueue_callback_url = xqueue_callback_url
self.xqueue_default_queuename = xqueue_default_queuename
self.xqueue = xqueue
self.track_function = track_function
self.filestore = filestore
self.get_module = get_module
......
......@@ -8,6 +8,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from xmodule.modulestore.django import modulestore
from capa.xqueue_interface import qinterface
from mitxmako.shortcuts import render_to_string
from models import StudentModule, StudentModuleCache
from static_replace import replace_urls
......@@ -151,6 +152,10 @@ def get_module(user, request, location, student_module_cache, position=None):
# TODO: Queuename should be derived from 'course_settings.json' of each course
xqueue_default_queuename = descriptor.location.org + '-' + descriptor.location.course
xqueue = { 'interface': qinterface,
'callback_url': xqueue_callback_url,
'default_queuename': xqueue_default_queuename.replace(' ','_') }
def _get_module(location):
(module, _, _, _) = get_module(user, request, location,
student_module_cache, position)
......@@ -162,8 +167,7 @@ def get_module(user, request, location, student_module_cache, position=None):
system = ModuleSystem(track_function=make_track_function(request),
render_template=render_to_string,
ajax_url=ajax_url,
xqueue_callback_url=xqueue_callback_url,
xqueue_default_queuename=xqueue_default_queuename.replace(' ','_'),
xqueue=xqueue,
# TODO (cpennington): Figure out how to share info between systems
filestore=descriptor.system.resources_fs,
get_module=_get_module,
......@@ -214,6 +218,9 @@ def get_module(user, request, location, student_module_cache, position=None):
@csrf_exempt
def xqueue_callback(request, userid, id, dispatch):
'''
Entry point for graded results from the queueing system.
'''
# Parse xqueue response
get = request.POST.copy()
try:
......
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