some obvious fixes
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 20 Jun 2013 11:06:56 +0000 (13:06 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 20 Jun 2013 11:06:56 +0000 (13:06 +0200)
librarian/pyhtml.py
librarian/pypdf.py

index 1f1f3df..7047cc9 100644 (file)
@@ -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 '<li><span data-solution="%s" data-no="%s" class="question-piece draggable handle add-li">%s</span>' % (element.attrib['rozw'], self.piece_counter, self.piece_counter), '</li>'
+                return '<li><span data-solution="%s" data-no="%s" class="question-piece draggable handle add-li">%s</span>' % (element.attrib.get('rozw', ''), self.piece_counter, self.piece_counter), '</li>'
             else:
-                return '<li data-solution="%s" data-no="%s" class="question-piece draggable">' % (element.attrib['rozw'], self.piece_counter), '</li>'
+                return '<li data-solution="%s" data-no="%s" class="question-piece draggable">' % (element.attrib.get('rozw', ''), self.piece_counter), '</li>'
 
         elif self.options['predicate']:
             if self.options['min']:
                 placeholders = u'<li class="placeholder"></li>' * self.options['min']
             else:
                 placeholders = u'<li class="placeholder multiple"></li>'
-            return '<li data-predicate="%(nazwa)s">' % element.attrib, '<ul class="subjects">' + placeholders + '</ul></li>'
+            return '<li data-predicate="%s">' % element.attrib.get('nazwa', ''), '<ul class="subjects">' + placeholders + '</ul></li>'
 
         else:
             return super(Przyporzadkuj, self).handle_punkt(element)
index d89d4af..b261eb6 100644 (file)
@@ -220,7 +220,10 @@ class EduModule(Xmill):
         }
         submill = EduModule(self.options)
 
-        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])
@@ -375,7 +378,7 @@ class EduModule(Xmill):
 
     def handle_obraz(self, element):
         frmt = self.options['format']
-        name = element.attrib['nazwa'].strip()
+        name = element.attrib.get('nazwa', '').strip()
         image = frmt.get_image(name.strip())
         img_path = "obraz/%s" % name.replace("_", "")
         frmt.attachments[img_path] = image
@@ -469,13 +472,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
@@ -552,7 +555,7 @@ class Zastap(Luki):
         return question.xpath(".//zastap")
 
     def solution(self, piece):
-        return piece.attrib['rozw']
+        return piece.attrib.get('rozw', '')
 
     def list_header(self):
         return u"Elementy do wstawienia"