Commit a077249a by Piotr Mitros

AJAX problems work

parent 7c2743d2
...@@ -13,6 +13,11 @@ from django.conf import settings ...@@ -13,6 +13,11 @@ from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string from djangomako.shortcuts import render_to_response, render_to_string
class LoncapaModule(XModule): 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"] xml_tags=["problem"]
id_attribute="filename" id_attribute="filename"
...@@ -25,12 +30,15 @@ class LoncapaModule(XModule): ...@@ -25,12 +30,15 @@ class LoncapaModule(XModule):
def max_score(self): def max_score(self):
return len(lcp.questions) return len(lcp.questions)
def get_html(self): def get_html(self, encapsulate=True):
inner_html=self.lcp.get_html() html = self.lcp.get_html()
content={'name':self.name, content={'name':self.name,
'html':inner_html} 'html':html}
return render_to_string('problem.html', html=render_to_string('problem.html',
{'problem':content, 'id':self.filename, 'done':self.lcp.done}) {'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): 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) XModule.__init__(self, xml, item_id, ajax_url, track_url, state)
...@@ -39,7 +47,7 @@ class LoncapaModule(XModule): ...@@ -39,7 +47,7 @@ class LoncapaModule(XModule):
self.filename=node.getAttribute("filename") self.filename=node.getAttribute("filename")
filename=settings.DATA_DIR+self.filename+".xml" filename=settings.DATA_DIR+self.filename+".xml"
self.name=node.getAttribute("name") 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): def handle_ajax(self, dispatch, get):
if dispatch=='problem_check': if dispatch=='problem_check':
...@@ -72,4 +80,9 @@ class LoncapaModule(XModule): ...@@ -72,4 +80,9 @@ class LoncapaModule(XModule):
self.lcp.answers=dict() # Student answers self.lcp.answers=dict() # Student answers
self.lcp.correct_map=dict() self.lcp.correct_map=dict()
self.lcp.seed=None 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(): ...@@ -37,6 +37,7 @@ class LoncapaProblem():
seed will provide the random seed. Alternatively, passing seed will provide the random seed. Alternatively, passing
context will bypass all script execution, and use the context will bypass all script execution, and use the
given execution context. ''' given execution context. '''
print "!!",filename, id
if state!=None: if state!=None:
state=json.loads(state) state=json.loads(state)
else: else:
......
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