Commit ce85762f by Piotr Mitros

Bug fix. Had a few things as class variables instead of instance variables that…

Bug fix. Had a few things as class variables instead of instance variables that were leaving profile in an inconsistent state.
parent 9b050cae
...@@ -24,10 +24,6 @@ class LoncapaModule(XModule): ...@@ -24,10 +24,6 @@ class LoncapaModule(XModule):
xml_tags = ["problem"] xml_tags = ["problem"]
id_attribute = "filename" id_attribute = "filename"
attempts = 0
max_attempts = None
due_date = None
def get_state(self): def get_state(self):
state = self.lcp.get_state() state = self.lcp.get_state()
...@@ -94,6 +90,11 @@ class LoncapaModule(XModule): ...@@ -94,6 +90,11 @@ class LoncapaModule(XModule):
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)
self.attempts = 0
self.max_attempts = None
self.due_date = None
dom=parseString(xml) dom=parseString(xml)
node=dom.childNodes[0] node=dom.childNodes[0]
......
...@@ -44,8 +44,19 @@ class LoncapaProblem(): ...@@ -44,8 +44,19 @@ 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. '''
self.done=False
self.text=""
self.context=dict() # Execution context from loncapa/python
self.questions=dict() # Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self.answers=dict() # Student answers
self.correct_map=dict()
self.seed=None
self.gid="" # ID of the problem
self.lid=-1 # ID of the field within the problem
if state==None: if state==None:
state={} state=dict()
self.gid=id self.gid=id
if 'done' in state: if 'done' in state:
...@@ -77,7 +88,6 @@ class LoncapaProblem(): ...@@ -77,7 +88,6 @@ class LoncapaProblem():
# Loop through the nodes of the problem, and # Loop through the nodes of the problem, and
for e in dom.childNodes: for e in dom.childNodes:
if e.localName=='script': if e.localName=='script':
#print e.childNodes[0].data
exec e.childNodes[0].data in g,self.context exec e.childNodes[0].data in g,self.context
elif e.localName=='endouttext': elif e.localName=='endouttext':
ot=False ot=False
...@@ -97,16 +107,6 @@ class LoncapaProblem(): ...@@ -97,16 +107,6 @@ class LoncapaProblem():
self.text=self.contextualize_text(self.text) self.text=self.contextualize_text(self.text)
self.filename=filename self.filename=filename
done=False
text=""
context={} # Execution context from loncapa/python
questions={} # Detailed info about questions in problem instance. TODO: Should be by id and not lid.
answers={} # Student answers
correct_map={}
seed=None
gid="" # ID of the problem
lid=-1 # ID of the field within the problem
def get_context(self): def get_context(self):
''' Return the execution context ''' ''' Return the execution context '''
return self.context return self.context
...@@ -131,14 +131,12 @@ class LoncapaProblem(): ...@@ -131,14 +131,12 @@ class LoncapaProblem():
correct_map[id]='incorrect' # Should always be there correct_map[id]='incorrect' # Should always be there
else: else:
grader=self.graders[self.questions[key]['type']] grader=self.graders[self.questions[key]['type']]
print grader
correct_map[id]=grader(self, self.questions[key], correct_map[id]=grader(self, self.questions[key],
self.answers[id]) self.answers[id])
self.correct_map=correct_map self.correct_map=correct_map
return correct_map return correct_map
def handle_schem(self, element): def handle_schem(self, element):
print element
height = element.getAttribute('height') height = element.getAttribute('height')
width = element.getAttribute('width') width = element.getAttribute('width')
if height=="": if height=="":
...@@ -151,7 +149,6 @@ class LoncapaProblem(): ...@@ -151,7 +149,6 @@ class LoncapaProblem():
html='<input type="hidden" class="schematic" name="input_{id}" '+ \ html='<input type="hidden" class="schematic" name="input_{id}" '+ \
'height="{height}" width="{width}" value="{value}" id="input_{id}">' 'height="{height}" width="{width}" value="{value}" id="input_{id}">'
html = html.format(height=height, width=width, id=id, value="") html = html.format(height=height, width=width, id=id, value="")
print html
return html return html
...@@ -196,7 +193,6 @@ class LoncapaProblem(): ...@@ -196,7 +193,6 @@ class LoncapaProblem():
return html return html
def grade_fr(self, question, answer): def grade_fr(self, question, answer):
print question, answer
correct = True correct = True
for i in range(question['samples_count']): for i in range(question['samples_count']):
instructor_variables = strip_dict(dict(self.context)) instructor_variables = strip_dict(dict(self.context))
...@@ -207,7 +203,6 @@ class LoncapaProblem(): ...@@ -207,7 +203,6 @@ class LoncapaProblem():
student_variables[str(var)] = value student_variables[str(var)] = value
instructor_result = evaluator(instructor_variables,{},str(question['answer'])) instructor_result = evaluator(instructor_variables,{},str(question['answer']))
student_result = evaluator(student_variables,{},str(answer)) student_result = evaluator(student_variables,{},str(answer))
print student_result, instructor_result
if math.isnan(student_result) or math.isinf(student_result): if math.isnan(student_result) or math.isinf(student_result):
return "incorrect" return "incorrect"
if abs( student_result - instructor_result ) > question['tolerance']: if abs( student_result - instructor_result ) > question['tolerance']:
......
...@@ -70,7 +70,6 @@ def seq_module(request, module): ...@@ -70,7 +70,6 @@ def seq_module(request, module):
params={'items':contents, params={'items':contents,
'id':"seq"} 'id':"seq"}
print module.nodeName
if module.nodeName == 'sequential': if module.nodeName == 'sequential':
return {'init_js':js+render_to_string('seq_module.js',params), return {'init_js':js+render_to_string('seq_module.js',params),
"destroy_js":"", "destroy_js":"",
...@@ -145,7 +144,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -145,7 +144,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
id_tag=modx_modules[module].id_attribute id_tag=modx_modules[module].id_attribute
#print "X",s.xml, "Y",content_parser.module_xml(module, id_tag, id) #print "X",s.xml, "Y",content_parser.module_xml(module, id_tag, id)
print
xml = content_parser.module_xml(content_parser.course_file(request.user), module, id_tag, id) xml = content_parser.module_xml(content_parser.course_file(request.user), module, id_tag, id)
......
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