X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/79da3449684beeb938735346e1d66093f51ba36d..aeed223c57f453d068216f86941b7de963190536:/librarian/pyhtml.py diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index bd3bbce..d3314cc 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -94,7 +94,8 @@ class EduModule(Xmill): 'uporzadkuj': Uporzadkuj, 'luki': Luki, 'zastap': Zastap, - 'przyporzadkuj': Przyporzadkuj + 'przyporzadkuj': Przyporzadkuj, + 'prawdafalsz': PrawdaFalsz } typ = element.attrib['typ'] @@ -137,16 +138,19 @@ class Excercise(EduModule): self.question_counter = 0 super(Excercise, self).__init__(*args, **kw) + def handle_rozw_kom(self, element): + return None + def handle_cwiczenie(self, element): self.options = {'excercise': element.attrib['typ']} self.question_counter = 0 self.piece_counter = 0 - return u""" + pre = u"""
-""" % element.attrib, \ -u""" +""" % element.attrib + post = u"""
@@ -155,8 +159,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) @@ -165,7 +177,7 @@ u""" return '
' %\ (self.question_counter, solution_s), \ - "
" + "
" class Wybor(Excercise): @@ -175,8 +187,9 @@ class Wybor(Excercise): self.piece_counter += 1 no = self.piece_counter eid = "q%(qc)d_%(no)d" % locals() + aname = element.attrib.get('nazwa', None) return u""" -
  • +
  • " @@ -186,16 +199,18 @@ class Wybor(Excercise): class Uporzadkuj(Excercise): - def handle_cwiczenie(self, element): - pre, post = super(Uporzadkuj, self).handle_cwiczenie(element) + def handle_pytanie(self, element): + """ +Overrides the returned content default handle_pytanie + """ + # we ignore the result, returning our own + super(Uporzadkuj, self).handle_pytanie(element) order_items = element.xpath(".//punkt/@rozw") - import pdb - if order_items == []: pdb.set_trace() - return pre + u"""
    """ % \ - ','.join(order_items), \ - u"""
    """ + post - + return u"""
    """ % \ + (','.join(order_items), self.question_counter), \ + u"""
    """ + def handle_punkt(self, element): return """
  • """ \ % element.attrib,\ @@ -207,7 +222,6 @@ class Luki(Excercise): return '' % element.text - class Zastap(Excercise): def handle_zastap(self, element): return '' % element.attrib, '' @@ -230,20 +244,31 @@ class Przyporzadkuj(Excercise): self.options = {'subject': True} else: attrs = {} - return super(Przyporzadkuj, self).handle_lista(lista, attrs) - + pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs) + return pre, post + '
    ' def handle_punkt(self, element): print "in punkt %s %s" % (element.attrib, self.options) if self.options['subject']: - return '
  • ' % element.attrib, '
  • ' + return '
  • ' % element.attrib, '
  • ' elif self.options['predicate']: - return '
  • ' % element.attrib, '
  • ' + print etree.tostring(element, encoding=unicode) + return '
  • ' % element.attrib, '
  • ' else: return super(Przyporzadkuj, self).handle_punkt(element) +class PrawdaFalsz(Excercise): + def handle_punkt(self, element): + if 'rozw' in element.attrib: + return u'''
  • + + Prawda + Fałsz + ''' % {'prawda': 'true', 'falsz': 'false'}[element.attrib['rozw']], '
  • ' + else: + return super(PrawdaFalsz, self).handle_punkt(element) def transform(wldoc, stylesheet='edumed', options=None, flags=None): @@ -253,7 +278,6 @@ def transform(wldoc, stylesheet='edumed', options=None, flags=None): otherwise returns True if file has been written,False if it hasn't. File won't be written if it has no content. """ - edumod = EduModule(options) # from pdb import set_trace; set_trace() html = edumod.generate(wldoc.edoc.getroot())