+ self.piece_counter += 1
+ return '<span class="placeholder zastap question-piece" data-solution="%d">' \
+ % self.piece_counter, '</span>'
+
+
+class Przyporzadkuj(Exercise):
+ INSTRUCTION = [u"Przeciągnij odpowiedzi i upuść w wybranym polu.",
+ u"Kliknij numer odpowiedzi, przeciągnij i upuść w wybranym polu."]
+
+ def get_instruction(self):
+ if not self.instruction_printed:
+ self.instruction_printed = True
+ return u'<span class="instruction">%s</span>' % self.INSTRUCTION[self.options['handles'] and 1 or 0]
+ else:
+ return ""
+
+ def handle_cwiczenie(self, element):
+ pre, post = super(Przyporzadkuj, self).handle_cwiczenie(element)
+ lista_with_handles = element.xpath(".//*[@uchwyty]")
+ if lista_with_handles:
+ self.options = {'handles': True}
+ return pre, post
+
+ 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}
+ 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 add-li">%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)