X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/0d3fb261fc396c2f8f66018ff923bf202e869b35..ba8c5f53b309b7ee2d993397e24640615777ab16:/librarian/pyhtml.py diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 64629d7..909217a 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -13,29 +13,6 @@ class EduModule(Xmill): super(EduModule, self).__init__(*args) self.activity_counter = 0 - - -# def handle_utwor(self, element): -# v = {} -# # from pdb import *; set_trace() -# v['title'] = element.xpath('//dc:title/text()', namespaces={'dc':DCNS.uri})[0] -# return u""" -# -# -# -# -# %(title)s -# -# -# -# -# -# """ % v, u""" -# -# -# """ - - def handle_powiesc(self, element): return u"""
@@ -114,7 +91,10 @@ class EduModule(Xmill): def handle_cwiczenie(self, element): excercise_handlers = { 'wybor': Wybor, - 'uporzadkuj': Uporzadkuj + 'uporzadkuj': Uporzadkuj, + 'luki': Luki, + 'zastap': Zastap, + 'przyporzadkuj': Przyporzadkuj } typ = element.attrib['typ'] @@ -122,7 +102,7 @@ class EduModule(Xmill): return handler.generate(element) # Lists - def handle_lista(self, element): + def handle_lista(self, element, attrs={}): ltype = element.attrib.get('typ', 'punkt') if ltype == 'slowniczek': self.options = {'slowniczek': True} @@ -133,7 +113,13 @@ class EduModule(Xmill): 'alfa': 'ul', 'czytelnia': 'ul'}[ltype] - return '<%s class="lista %s">' % (listtag, ltype), '' % listtag + 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), '' % listtag def handle_punkt(self, element): if self.options['slowniczek']: @@ -156,11 +142,11 @@ class Excercise(EduModule): self.question_counter = 0 self.piece_counter = 0 - return u""" + pre = u"""
-""" % element.attrib, \ -u""" +""" % element.attrib + post = u"""
@@ -169,8 +155,16 @@ u"""
""" + # Add a single 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 element, when there is no + """ self.question_counter += 1 self.piece_counter = 0 solution = element.attrib.get('rozw', None) @@ -190,7 +184,9 @@ class Wybor(Excercise): no = self.piece_counter eid = "q%(qc)d_%(no)d" % locals() return u""" -
  • + +
  • " else: @@ -201,7 +197,6 @@ class Uporzadkuj(Excercise): def handle_cwiczenie(self, element): pre, post = super(Uporzadkuj, self).handle_cwiczenie(element) order_items = element.xpath(".//punkt/@rozw") - import pdb if order_items == []: pdb.set_trace() return pre + u"""
    """ % \ @@ -209,19 +204,51 @@ class Uporzadkuj(Excercise): u"""
    """ + post def handle_punkt(self, element): - return """
  • """ % element.attrib,\ + return """
  • """ \ + % element.attrib,\ "
  • " class Luki(Excercise): def handle_luka(self, element): - return '' % element.text, \ - '' + return '' % element.text + class Zastap(Excercise): def handle_zastap(self, element): - return '' % element.attrib, '' + return '' % element.attrib, '' + + +class Przyporzadkuj(Excercise): + def handle_lista(self, lista): + print "in lista %s %s" % (lista.attrib, self.options) + 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 = {} + return super(Przyporzadkuj, self).handle_lista(lista, attrs) + + + def handle_punkt(self, element): + print "in punkt %s %s" % (element.attrib, self.options) + + if self.options['subject']: + return '
  • ' % element.attrib, '
  • ' + elif self.options['predicate']: + return '
  • ' % element.attrib, '
    • Placeholder
  • ' + else: + return super(Przyporzadkuj, self).handle_punkt(element)