X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/515398ba21b6ac3c0db230a465cfc8528db8d10e..e9cdd3f1f653de79f94ddfcdf319fcc31e7f0cef:/librarian/pyhtml.py diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 1f1f3df..7047cc9 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -93,7 +93,10 @@ class EduModule(Xmill): } submill = EduModule(dict(self.options.items() + {'sub_gen': True}.items())) - opis = submill.generate(element.xpath('opis')[0]) + if element.xpath('opis'): + opis = submill.generate(element.xpath('opis')[0]) + else: + opis = '' n = element.xpath('wskazowki') if n: wskazowki = submill.generate(n[0]) @@ -396,13 +399,13 @@ class Wybor(Exercise): if not pytania: pytania = [element] for p in pytania: - solutions = re.split(r"[, ]+", p.attrib['rozw']) + solutions = re.split(r"[, ]+", p.attrib.get('rozw', '')) if len(solutions) != 1: is_single_choice = False break choices = p.xpath(".//*[@nazwa]") uniq = set() - for n in choices: uniq.add(n.attrib['nazwa']) + for n in choices: uniq.add(n.attrib.get('nazwa', '')) if len(choices) != len(uniq): is_single_choice = False break @@ -496,7 +499,7 @@ class Zastap(Luki): return question.xpath(".//zastap") def solution_html(self, piece): - return piece.attrib['rozw'] + return piece.attrib.get('rozw', '') def handle_zastap(self, element): self.piece_counter += 1 @@ -551,16 +554,16 @@ class Przyporzadkuj(Exercise): if self.options['subject']: self.piece_counter += 1 if self.options['handles']: - return '
  • %s' % (element.attrib['rozw'], self.piece_counter, self.piece_counter), '
  • ' + return '
  • %s' % (element.attrib.get('rozw', ''), self.piece_counter, self.piece_counter), '
  • ' else: - return '
  • ' % (element.attrib['rozw'], self.piece_counter), '
  • ' + return '
  • ' % (element.attrib.get('rozw', ''), self.piece_counter), '
  • ' elif self.options['predicate']: if self.options['min']: placeholders = u'
  • ' * self.options['min'] else: placeholders = u'
  • ' - return '
  • ' % element.attrib, '
  • ' + return '
  • ' % element.attrib.get('nazwa', ''), '
  • ' else: return super(Przyporzadkuj, self).handle_punkt(element)