self.question_counter = 0
super(Excercise, self).__init__(*args, **kw)
+ def handle_rozw_kom(self, element):
+ return None
+
def handle_cwiczenie(self, element):
self.options = {'excercise': element.attrib['typ']}
self.question_counter = 0
self.piece_counter = 0
- return u"""
+ pre = u"""
<div class="excercise %(typ)s" data-type="%(typ)s">
<form action="#" method="POST">
-""" % element.attrib, \
-u"""
+""" % element.attrib
+ post = u"""
<div class="buttons">
<span class="message"></span>
<input type="button" class="check" value="sprawdź"/>
</form>
</div>
"""
+ # Add a single <pytanie> tag if it's not there
+ if not element.xpath(".//pytanie"):
+ qpre, qpost = self.handle_pytanie(element)
+ pre = pre + qpre
+ post = qpost + post
+ return pre, post
def handle_pytanie(self, element):
+ """This will handle <cwiczenie> element, when there is no <pytanie>
+ """
self.question_counter += 1
self.piece_counter = 0
solution = element.attrib.get('rozw', None)
return '<div class="question" data-no="%d" %s>' %\
(self.question_counter, solution_s), \
- "</div>"
+ "</div>"
class Wybor(Excercise):
class Uporzadkuj(Excercise):
- def handle_cwiczenie(self, element):
- pre, post = super(Uporzadkuj, self).handle_cwiczenie(element)
+ def handle_pytanie(self, element):
+ """
+Overrides the returned content default handle_pytanie
+ """
+ # we ignore the result, returning our own
+ super(Uporzadkuj, self).handle_pytanie(element)
order_items = element.xpath(".//punkt/@rozw")
- import pdb
- if order_items == []: pdb.set_trace()
- return pre + u"""<div class="question" data-original="%s">""" % \
- ','.join(order_items), \
- u"""</div>""" + post
-
+ return u"""<div class="question" data-original="%s" data-no="%s">""" % \
+ (','.join(order_items), self.question_counter), \
+ u"""</div>"""
+
def handle_punkt(self, element):
return """<li class="question-piece" data-pos="%(rozw)s"/>""" \
% element.attrib,\
return '<input type="text" class="luka question-piece" data-solution="%s"></input>' % element.text
-
class Zastap(Excercise):
def handle_zastap(self, element):
return '<span class="zastap question-piece" data-solution="%(rozw)s">' % element.attrib, '</span>'
self.options = {'subject': True}
else:
attrs = {}
- return super(Przyporzadkuj, self).handle_lista(lista, attrs)
-
+ pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs)
+ return pre, post + '<br class="clr"/>'
def handle_punkt(self, element):
print "in punkt %s %s" % (element.attrib, self.options)
if self.options['subject']:
- return '<li data-solution="%(rozw)s" class="question-piece draggable multiple">' % element.attrib, '</li>'
+ return '<li data-solution="%(rozw)s" class="question-piece draggable">' % element.attrib, '</li>'
elif self.options['predicate']:
- return '<li data-predicate="%(nazwa)s">' % element.attrib, '<ul class="subjects droppable"><li>Placeholder</li></ul></li>'
+ return '<li data-predicate="%(nazwa)s">' % element.attrib, '<ul class="subjects droppable"></ul></li>'
else:
return super(Przyporzadkuj, self).handle_punkt(element)
-
-
def transform(wldoc, stylesheet='edumed', options=None, flags=None):
"""Transforms the WL document to XHTML.
otherwise returns True if file has been written,False if it hasn't.
File won't be written if it has no content.
"""
-
edumod = EduModule(options)
# from pdb import set_trace; set_trace()
html = edumod.generate(wldoc.edoc.getroot())