Commit 40d7e8ad by Will Daly

Moved problem HTML error handling to its own function

parent 60855242
......@@ -319,13 +319,15 @@ class CapaModule(XModule):
else:
return True
def get_problem_html(self, encapsulate=True):
'''Return html for the problem. Adds check, reset, save buttons
as necessary based on the problem config and state.'''
def handle_problem_html_error(self, err):
"""
Change our problem to a dummy problem containing
a warning message to display to users.
try:
html = self.lcp.get_html()
except Exception, err:
Returns the HTML to show to users
*err* is the Exception encountered while rendering the problem HTML.
"""
log.exception(err)
# TODO (vshnayder): another switch on DEBUG.
......@@ -337,9 +339,10 @@ class CapaModule(XModule):
msg += '<p>Error:</p><p><pre>%s</pre></p>' % str(err).replace('<', '&lt;')
msg += '<p><pre>%s</pre></p>' % traceback.format_exc().replace('<', '&lt;')
html = msg
else:
# We're in non-debug mode, and possibly even in production. We want
# to avoid bricking of problem as much as possible
else:
# Presumably, student submission has corrupted LoncapaProblem HTML.
# First, pull down all student answers
......@@ -380,6 +383,19 @@ class CapaModule(XModule):
log.exception(err)
raise
return html
def get_problem_html(self, encapsulate=True):
'''Return html for the problem. Adds check, reset, save buttons
as necessary based on the problem config and state.'''
try:
html = self.lcp.get_html()
except Exception, err:
return self.handle_problem_html_error(err)
content = {'name': self.display_name,
'html': html,
'weight': self.descriptor.weight,
......
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