diff --git a/djangoapps/courseware/capa/responsetypes.py b/djangoapps/courseware/capa/responsetypes.py index c173eb6..9ba1bd6 100644 --- a/djangoapps/courseware/capa/responsetypes.py +++ b/djangoapps/courseware/capa/responsetypes.py @@ -38,7 +38,6 @@ class numericalresponse(object): def __init__(self, xml, context): self.xml = xml self.correct_answer = contextualize_text(xml.get('answer'), context) - self.correct_answer = complex(self.correct_answer) self.tolerance_xml = xml.xpath('//*[@id=$id]//responseparam[@type="tolerance"]/@default', id=xml.get('id'))[0] self.tolerance = contextualize_text(self.tolerance_xml, context) diff --git a/djangoapps/courseware/modules/capa_module.py b/djangoapps/courseware/modules/capa_module.py index 17ee626..7ec92ec 100644 --- a/djangoapps/courseware/modules/capa_module.py +++ b/djangoapps/courseware/modules/capa_module.py @@ -26,6 +26,12 @@ import courseware.content_parser as content_parser log = logging.getLogger("mitx.courseware") +class ComplexEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, complex): + return "{real:.7g}{imag:+.7g}*j".format(real = obj.real,imag = obj.imag) + return json.JSONEncoder.default(self, obj) + class Module(XModule): ''' Interface between capa_problem and x_module. Originally a hack meant to be refactored out, but it seems to be serving a useful @@ -240,7 +246,8 @@ class Module(XModule): if not self.answer_available(): raise Http404 else: - return json.dumps(self.lcp.get_question_answers()) + return json.dumps(self.lcp.get_question_answers(), + cls=ComplexEncoder) # Figure out if we should move these to capa_problem?