X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/d0475d381f12b2c89c7c514c4f7f7d2ebc421d0a..935dcf2282ee3c08f776e221bc71f9a0744cb85e:/librarian/pyhtml.py diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 4f8f98c..3bda4c8 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -131,7 +131,7 @@ class EduModule(Xmill): counter = self.activity_counter - if element.getnext().tag == 'aktywnosc' or (self.activity_last and self.activity_last.getnext() == element): + if element.getnext().tag == 'aktywnosc' or (len(self.activity_last) and self.activity_last.getnext() == element): counter_html = """%(counter)d.""" % {'counter': counter} else: counter_html = '' @@ -251,7 +251,7 @@ class EduModule(Xmill): subgen = EduModule(self.options) definiens_s = subgen.generate(definiens) else: - print "!! Missing definiendum in source: '%s'" % element.text + print ("!! Missing definiendum in source: '%s'" % element.text).encode('utf-8') return u"
" % self.naglowek_to_anchor(element), u"
" + definiens_s @@ -351,13 +351,18 @@ class Exercise(EduModule): def handle_rozw_kom(self, element): return u"""""" + def extra_attributes(self): + return {} + def handle_cwiczenie(self, element): self.options = {'exercise': element.attrib['typ']} self.question_counter = 0 self.piece_counter = 0 + extra_attrs = self.extra_attributes() + pre = u""" -
+

Zadanie %(exercies_counter)d

@@ -368,7 +373,12 @@ class Exercise(EduModule):
-""" % {'exercies_counter': self.options['exercise_counter'], 'typ': element.attrib['typ']} +""" % { + 'exercies_counter': self.options['exercise_counter'], + 'typ': element.attrib['typ'], + 'extra_attrs': ' ' + ' '.join( + 'data-%s="%s"' % item for item in extra_attrs.iteritems()) if extra_attrs else '', + } post = u"""
@@ -420,48 +430,39 @@ class Exercise(EduModule): class Wybor(Exercise): + def extra_attributes(self): + return {'subtype': 'single' if self.options['single'] else 'multiple'} + def handle_cwiczenie(self, element): - pre, post = super(Wybor, self).handle_cwiczenie(element) is_single_choice = True pytania = element.xpath(".//pytanie") if not pytania: pytania = [element] for p in pytania: - solutions = re.split(r"[, ]+", p.attrib.get('rozw', '')) + solutions = p.xpath(".//punkt[@rozw='prawda']") if len(solutions) != 1: is_single_choice = False break - choices = p.xpath(".//*[@nazwa]") - uniq = set() - for n in choices: - uniq.add(n.attrib.get('nazwa', '')) - if len(choices) != len(uniq): - is_single_choice = False - break self.options = {'single': is_single_choice} - return pre, post + return super(Wybor, self).handle_cwiczenie(element) def handle_punkt(self, element): - if self.options['exercise'] and element.attrib.get('nazwa', None): + if self.options['exercise'] and element.attrib.get('rozw', None): qc = self.question_counter self.piece_counter += 1 no = self.piece_counter eid = "q%(qc)d_%(no)d" % locals() - aname = element.attrib.get('nazwa', None) + sol = element.attrib.get('rozw', None) + params = {'qc': qc, 'no': no, 'sol': sol, 'eid': eid} if self.options['single']: - return u""" -
  • - -
  • " + input_tag = u'' else: - return u""" -
  • - -
  • " - + input_tag = u'' + return (u""" +
  • + """ + input_tag + u""" +
  • " else: return super(Wybor, self).handle_punkt(element) @@ -659,7 +660,7 @@ class EduModuleFormat(Format): order = {pmf: i for (i, pmf) in enumerate(self.PRIMARY_MATERIAL_FORMATS)} mats = self.materials_by_slug.get(slug, {}).items() if not mats: - print "!! Material missing: '%s'" % slug + print ("!! Material missing: '%s'" % slug).encode('utf-8') return sorted(mats, key=lambda (x, y): order.get(x, x)) def url_for_material(self, slug, fmt):