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:
@@ -475,12 +475,11 @@ class LoncapaProblem(object):
|
||||
msg = "Error while executing script code: %s" % str(err).replace('<', '<')
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user