Commit 41e7d72e by kimth

Xqueue interface is embedded in ModuleSystem

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