+class Luki(Exercise):
+ def find_pieces(self, question):
+ return question.xpath(".//luka")
+
+ def solution_html(self, piece):
+ return piece.text + ''.join(
+ [etree.tostring(n, encoding=unicode)
+ for n in piece])
+
+ def handle_pytanie(self, element):
+ qpre, qpost = super(Luki, self).handle_pytanie(element)
+
+ luki = list(enumerate(self.find_pieces(element)))
+ luki_html = ""
+ i = 0
+ random.shuffle(luki)
+ for (i, luka) in luki:
+ i += 1
+ luka_html = self.solution_html(luka)
+ luki_html += u'<span class="draggable question-piece" data-no="%d">%s</span>' % (i, luka_html)
+ self.words_html = '<div class="words">%s</div>' % luki_html
+
+ return qpre, qpost
+
+ def handle_opis(self, element):
+ return '', self.words_html
+
+ def handle_luka(self, element):
+ self.piece_counter += 1
+ return '<span class="placeholder" data-solution="%d"></span>' % self.piece_counter
+
+
+class Zastap(Luki):
+ def find_pieces(self, question):
+ return question.xpath(".//zastap")
+
+ def solution_html(self, piece):
+ return piece.attrib['rozw']
+
+ def handle_zastap(self, element):
+ self.piece_counter += 1
+ return '<span class="placeholder zastap question-piece" data-solution="%d">' \
+ % self.piece_counter, '</span>'
+
+
+class Przyporzadkuj(Exercise):
+ def handle_pytanie(self, element):
+ pre, post = super(Przyporzadkuj, self).handle_pytanie(element)
+ minimum = element.attrib.get("min", None)
+ if minimum:
+ self.options = {"min": int(minimum)}
+ return pre, post
+
+ def handle_lista(self, lista):
+ if 'nazwa' in lista.attrib:
+ attrs = {
+ 'data-name': lista.attrib['nazwa'],
+ 'class': 'predicate'
+ }
+ self.options = {'predicate': True}
+ elif 'cel' in lista.attrib:
+ attrs = {
+ 'data-target': lista.attrib['cel'],
+ 'class': 'subject'
+ }
+ self.options = {'subject': True, 'handles': 'uchwyty' in lista.attrib}
+ else:
+ attrs = {}
+ pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs)
+ return pre, post + '<br class="clr"/>'
+
+ def handle_punkt(self, element):
+ if self.options['subject']:
+ self.piece_counter += 1
+ if self.options['handles']:
+ return '<li><span data-solution="%s" data-no="%s" class="question-piece draggable handle">%s</span>' % (element.attrib['rozw'], self.piece_counter, self.piece_counter), '</li>'
+ else:
+ return '<li data-solution="%s" data-no="%s" class="question-piece draggable">' % (element.attrib['rozw'], self.piece_counter), '</li>'
+
+ elif self.options['predicate']:
+ if self.options['min']:
+ placeholders = u'<li class="placeholder"/>' * self.options['min']
+ else:
+ placeholders = u'<li class="placeholder multiple"/>'
+ return '<li data-predicate="%(nazwa)s">' % element.attrib, '<ul class="subjects">' + placeholders + '</ul></li>'
+
+ else:
+ return super(Przyporzadkuj, self).handle_punkt(element)
+
+
+class PrawdaFalsz(Exercise):
+ def handle_punkt(self, element):
+ if 'rozw' in element.attrib:
+ return u'''<li data-solution="%s" class="question-piece">
+ <span class="buttons">
+ <a href="#" data-value="true" class="true">Prawda</a>
+ <a href="#" data-value="false" class="false">Fałsz</a>
+ </span>''' % {'prawda': 'true', 'falsz': 'false'}[element.attrib['rozw']], '</li>'
+ else:
+ return super(PrawdaFalsz, self).handle_punkt(element)
+
+
+class EduModuleFormat(Format):
+ def __init__(self, wldoc, **kwargs):
+ super(EduModuleFormat, self).__init__(wldoc, **kwargs)
+
+ def build(self):
+ edumod = EduModule({'provider': self.wldoc.provider, 'urlmapper': self})
+
+ html = edumod.generate(self.wldoc.edoc.getroot())
+
+ return IOFile.from_string(html.encode('utf-8'))
+
+ def url_for_material(self, slug, fmt=None):
+ # No briliant idea for an API here.
+ if fmt:
+ return "%s.%s" % (slug, fmt)
+ return slug
+
+