AJAX problems work
This commit is contained in:
@@ -13,6 +13,11 @@ from django.conf import settings
|
||||
from djangomako.shortcuts import render_to_response, render_to_string
|
||||
|
||||
class LoncapaModule(XModule):
|
||||
''' Interface between capa_problem and x_module. Originally a hack
|
||||
meant to be refactored out, but it seems to be serving a useful
|
||||
prupose now. We can e.g .destroy and create the capa_problem on a
|
||||
reset.
|
||||
'''
|
||||
xml_tags=["problem"]
|
||||
id_attribute="filename"
|
||||
|
||||
@@ -25,12 +30,15 @@ class LoncapaModule(XModule):
|
||||
def max_score(self):
|
||||
return len(lcp.questions)
|
||||
|
||||
def get_html(self):
|
||||
inner_html=self.lcp.get_html()
|
||||
def get_html(self, encapsulate=True):
|
||||
html = self.lcp.get_html()
|
||||
content={'name':self.name,
|
||||
'html':inner_html}
|
||||
return render_to_string('problem.html',
|
||||
{'problem':content, 'id':self.filename, 'done':self.lcp.done})
|
||||
'html':html}
|
||||
html=render_to_string('problem.html',
|
||||
{'problem':content, 'id':self.filename, 'done':self.lcp.done})
|
||||
if encapsulate:
|
||||
html = '<div id="main_{id}">'.format(id=self.item_id)+html+"</div>"
|
||||
return html
|
||||
|
||||
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None):
|
||||
XModule.__init__(self, xml, item_id, ajax_url, track_url, state)
|
||||
@@ -39,7 +47,7 @@ class LoncapaModule(XModule):
|
||||
self.filename=node.getAttribute("filename")
|
||||
filename=settings.DATA_DIR+self.filename+".xml"
|
||||
self.name=node.getAttribute("name")
|
||||
self.lcp=LoncapaProblem(filename, item_id, state)
|
||||
self.lcp=LoncapaProblem(filename, self.item_id, state)
|
||||
|
||||
def handle_ajax(self, dispatch, get):
|
||||
if dispatch=='problem_check':
|
||||
@@ -72,4 +80,9 @@ class LoncapaModule(XModule):
|
||||
self.lcp.answers=dict() # Student answers
|
||||
self.lcp.correct_map=dict()
|
||||
self.lcp.seed=None
|
||||
return "{}"
|
||||
# Minor cleanup would be nice
|
||||
# We recreate the capa_problem on a reset
|
||||
filename=settings.DATA_DIR+self.filename+".xml"
|
||||
self.lcp=LoncapaProblem(filename, self.item_id, self.lcp.get_state())
|
||||
# self.lcp.__init__(filename, self.item_id, self.lcp.get_state())
|
||||
return json.dumps(self.get_html(encapsulate=False))
|
||||
|
||||
@@ -37,6 +37,7 @@ class LoncapaProblem():
|
||||
seed will provide the random seed. Alternatively, passing
|
||||
context will bypass all script execution, and use the
|
||||
given execution context. '''
|
||||
print "!!",filename, id
|
||||
if state!=None:
|
||||
state=json.loads(state)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user