X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/3b0b98465bc1862306b05bb8305a1abbf40ca310..f1ae0a40b774ad7260e7449986764c9104553e03:/librarian/pypdf.py diff --git a/librarian/pypdf.py b/librarian/pypdf.py index 9851cb1..920f1b9 100644 --- a/librarian/pypdf.py +++ b/librarian/pypdf.py @@ -29,7 +29,7 @@ def escape(really): def _wrap(*args, **kw): value = f(*args, **kw) - prefix = (u'' % (really and 1 or 0)) + prefix = (u'' % (1 if really else 0)) postfix = u'' if isinstance(value, list): import pdb @@ -83,7 +83,7 @@ class EduModule(Xmill): def get_dc(self, element, dc_field, single=False): values = map(lambda t: t.text, element.xpath("//dc:%s" % dc_field, namespaces={'dc': DCNS.uri})) if single: - return values[0] + return values[0] if len(values) else '' return values def handle_rdf__RDF(self, _): @@ -108,10 +108,17 @@ class EduModule(Xmill): authors = getattr(dc, "authors_%s" % which) return u', '.join(author.readable() for author in authors if author) - @escape(1) + @escape(True) def get_title(self, element): return self.get_dc(element, 'title', True) + @escape(True) + def get_description(self, element): + desc = self.get_dc(element, 'description', single=True) + if not desc: + print '!! no descripton' + return desc + def handle_utwor(self, element): lines = [ u''' @@ -130,6 +137,7 @@ class EduModule(Xmill): u'''\\def\\authorsexpert{%s}''' % self.get_authors(element, 'expert'), u'''\\def\\authorsscenario{%s}''' % self.get_authors(element, 'scenario'), u'''\\def\\authorstextbook{%s}''' % self.get_authors(element, 'textbook'), + u'''\\def\\description{%s}''' % self.get_description(element), u'''\\author{\\authors}''', u'''\\title{%s}''' % self.get_title(element), @@ -140,14 +148,14 @@ class EduModule(Xmill): return u"".join(filter(None, lines)), u'' - @escape(1) + @escape(True) def handle_powiesc(self, element): return u""" """, """""" - @escape(1) + @escape(True) def handle_texcommand(self, element): cmd = functions.texcommand(element.tag) return u'' % cmd, u'' @@ -261,7 +269,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_tex = """%(counter)d.""" % locals() else: counter_tex = '' @@ -386,11 +394,11 @@ class EduModule(Xmill): tabular%s ''' % ('l' * max_col), u'''tabular''' - @escape(1) + @escape(True) def handle_wiersz(self, element): return u"", u'' - @escape(1) + @escape(True) def handle_kol(self, element): if element.getnext() is not None: return u"", u''