Commit a30f1a1e by Piotr Mitros

Explain works

parent a7b5433c
...@@ -80,6 +80,16 @@ class LoncapaModule(XModule): ...@@ -80,6 +80,16 @@ class LoncapaModule(XModule):
if self.max_attempts != None: if self.max_attempts != None:
attempts_str = " ({a}/{m})".format(a=self.attempts, m=self.max_attempts) 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', html=render_to_string('problem.html',
{'problem' : content, {'problem' : content,
'id' : self.filename, 'id' : self.filename,
...@@ -88,7 +98,8 @@ class LoncapaModule(XModule): ...@@ -88,7 +98,8 @@ class LoncapaModule(XModule):
'save_button' : save_button, 'save_button' : save_button,
'answer_available' : self.answer_available(), 'answer_available' : self.answer_available(),
'ajax_url' : self.ajax_url, 'ajax_url' : self.ajax_url,
'attempts': attempts_str 'attempts': attempts_str,
'explain': explain
}) })
if encapsulate: if encapsulate:
html = '<div id="main_{id}">'.format(id=self.item_id)+html+"</div>" html = '<div id="main_{id}">'.format(id=self.item_id)+html+"</div>"
...@@ -104,6 +115,9 @@ class LoncapaModule(XModule): ...@@ -104,6 +115,9 @@ class LoncapaModule(XModule):
dom2 = etree.fromstring(xml) 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')) self.due_date=content_parser.item(dom2.xpath('/problem/@due'))
if len(self.due_date)>0: if len(self.due_date)>0:
self.due_date=dateutil.parser.parse(self.due_date) self.due_date=dateutil.parser.parse(self.due_date)
......
...@@ -17,8 +17,18 @@ class HtmlModule(XModule): ...@@ -17,8 +17,18 @@ class HtmlModule(XModule):
return "html" return "html"
def get_html(self): 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): 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) 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])
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