+class Luki(Excercise):
+ 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):
+ pre, post = super(Luki, self).handle_opis(element)
+ return pre, self.words_html + post
+
+ 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(Excercise):
+ 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}
+ 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']:
+ 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(Excercise):
+ 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)
+
+