From a30f1a1e99b789dda61037b7ae5edd0eb99db8ef Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Tue, 27 Dec 2011 21:08:06 -0500 Subject: [PATCH] Explain works --- courseware/capa_module.py | 16 +++++++++++++++- courseware/html_module.py | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/courseware/capa_module.py b/courseware/capa_module.py index 5120b07878..0948518bb7 100644 --- a/courseware/capa_module.py +++ b/courseware/capa_module.py @@ -80,6 +80,16 @@ class LoncapaModule(XModule): if self.max_attempts != None: attempts_str = " ({a}/{m})".format(a=self.attempts, m=self.max_attempts) + # Check if explanation is available, and if so, give a link + explain="" + if self.lcp.done and self.explain_available=='attempted': + explain=self.explanation + if self.closed() and self.explain_available=='closed': + explain=self.explanation + + if len(explain) == 0: + explain = False + html=render_to_string('problem.html', {'problem' : content, 'id' : self.filename, @@ -88,7 +98,8 @@ class LoncapaModule(XModule): 'save_button' : save_button, 'answer_available' : self.answer_available(), 'ajax_url' : self.ajax_url, - 'attempts': attempts_str + 'attempts': attempts_str, + 'explain': explain }) if encapsulate: html = '
'.format(id=self.item_id)+html+"
" @@ -104,6 +115,9 @@ class LoncapaModule(XModule): dom2 = etree.fromstring(xml) + self.explanation=content_parser.item(dom2.xpath('/problem/@explain')) + self.explain_available=content_parser.item(dom2.xpath('/problem/@explain_available')) + self.due_date=content_parser.item(dom2.xpath('/problem/@due')) if len(self.due_date)>0: self.due_date=dateutil.parser.parse(self.due_date) diff --git a/courseware/html_module.py b/courseware/html_module.py index b2f0c0a002..ceadb2fd8b 100644 --- a/courseware/html_module.py +++ b/courseware/html_module.py @@ -17,8 +17,18 @@ class HtmlModule(XModule): return "html" def get_html(self): - return render_to_string(self.item_id, {'id': self.item_id}) + if self.filename!=None: + return render_to_string(self.filename, {'id': self.item_id}) + else: + xmltree=etree.fromstring(self.xml) + textlist=[xmltree.text]+[etree.tostring(i) for i in xmltree]+[xmltree.tail] + textlist=[i for i in textlist if type(i)==str] + return "".join(textlist) def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None): XModule.__init__(self, xml, item_id, ajax_url, track_url, state) - print xml + xmltree=etree.fromstring(xml) + self.filename = None + filename_l=xmltree.xpath("/html/@filename") + if len(filename_l)>0: + self.filename=str(filename_l[0])