Commit 40d7e8ad by Will Daly

Moved problem HTML error handling to its own function

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