Check functions need access to course-local code also, so we need to save the python path from the problem setup, and use it for the check function.

This commit is contained in:
Ned Batchelder
2013-05-22 13:27:24 -04:00
parent 073c6d9a79
commit 392de8d40e
2 changed files with 4 additions and 5 deletions

View File

@@ -475,12 +475,11 @@ class LoncapaProblem(object):
msg = "Error while executing script code: %s" % str(err).replace('<', '&lt;')
raise responsetypes.LoncapaProblemError(msg)
# store code source in context
# Store code source in context, along with the Python path needed to run it correctly.
context['script_code'] = all_code
context['python_path'] = python_path
return context
def _extract_html(self, problemtree): # private
'''
Main (private) function which converts Problem XML tree to HTML.

View File

@@ -286,7 +286,7 @@ class LoncapaResponse(object):
}
try:
safe_exec.safe_exec(code, globals_dict)
safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path'])
except Exception as err:
msg = 'Error %s in evaluating hint function %s' % (err, hintfn)
msg += "\nSee XML source line %s" % getattr(
@@ -972,7 +972,7 @@ class CustomResponse(LoncapaResponse):
'ans': ans,
}
globals_dict.update(kwargs)
safe_exec.safe_exec(code, globals_dict, cache=self.system.cache)
safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path'])
return globals_dict['cfn_return']
return check_function