+
+ def handle_cwiczenie(self, element):
+ exercise_handlers = {
+ 'wybor': Wybor,
+ 'uporzadkuj': Uporzadkuj,
+ 'luki': Luki,
+ 'zastap': Zastap,
+ 'przyporzadkuj': Przyporzadkuj,
+ 'prawdafalsz': PrawdaFalsz
+ }
+
+ typ = element.attrib['typ']
+ handler = exercise_handlers[typ](self.options)
+ return handler.generate(element)
+
+ # Lists
+ def handle_lista(self, element, attrs={}):
+ ltype = element.attrib.get('typ', 'punkt')
+ if ltype == 'slowniczek':
+ surl = element.attrib.get('href', None)
+ sxml = None
+ if surl:
+ sxml = etree.fromstring(self.options['provider'].by_uri(surl).get_string())
+ self.options = {'slowniczek': True, 'slowniczek_xml': sxml }
+ return '<div class="slowniczek">', '</div>'
+
+ listtag = {'num': 'ol',
+ 'punkt': 'ul',
+ 'alfa': 'ul',
+ 'czytelnia': 'ul'}[ltype]
+
+ classes = attrs.get('class', '')
+ if classes: del attrs['class']
+
+ attrs_s = ' '.join(['%s="%s"' % kv for kv in attrs.items()])
+ if attrs_s: attrs_s = ' ' + attrs_s
+
+ return '<%s class="lista %s %s"%s>' % (listtag, ltype, classes, attrs_s), '</%s>' % listtag
+
+ def handle_punkt(self, element):
+ if self.options['slowniczek']:
+ return '<dl>', '</dl>'
+ else:
+ return '<li>', '</li>'
+
+ def handle_definiendum(self, element):
+ nxt = element.getnext()
+ definiens_s = ''
+
+ # let's pull definiens from another document
+ if self.options['slowniczek_xml'] and (not nxt or nxt.tag != 'definiens'):
+ sxml = self.options['slowniczek_xml']
+ assert element.text != ''
+ defloc = sxml.xpath("//definiendum[text()='%s']" % element.text)
+ if defloc:
+ definiens = defloc[0].getnext()
+ if definiens.tag == 'definiens':
+ subgen = EduModule(self.options)
+ definiens_s = subgen.generate(definiens)
+
+ return u"<dt>", u"</dt>" + definiens_s
+
+ def handle_definiens(self, element):
+ return u"<dd>", u"</dd>"
+
+
+ def handle_podpis(self, element):
+ return u"""<div class="caption">""", u"</div>"
+
+ def handle_tabela(self, element):
+ has_frames = int(element.attrib.get("ramki", "0"))
+ if has_frames: frames_c = "framed"
+ else: frames_c = ""
+ return u"""<table class="%s">""" % frames_c, u"</table>"
+
+ def handle_wiersz(self, element):
+ return u"<tr>", u"</tr>"
+
+ def handle_kol(self, element):
+ return u"<td>", u"</td>"
+
+ def handle_rdf__RDF(self, _):
+ # ustal w opcjach rzeczy :D
+ return
+
+ def handle_link(self, element):
+ if 'material' in element.attrib:
+ formats = re.split(r"[, ]+", element.attrib['format'])
+ fmt_links = []
+ for f in formats:
+ fmt_links.append(u'<a href="%s">%s</a>' % (self.options['urlmapper'].url_for_material(element.attrib['material'], f), f.upper()))
+
+ return u"", u' (%s)' % u' '.join(fmt_links)
+
+
+class Exercise(EduModule):
+ def __init__(self, *args, **kw):
+ self.question_counter = 0
+ super(Exercise, self).__init__(*args, **kw)
+
+ def handle_rozw_kom(self, element):
+ return u"""<div style="display:none" class="comment">""", u"""</div>"""
+