From: Radek Czajka Date: Wed, 10 Nov 2010 15:17:42 +0000 (+0100) Subject: fixes #938: dc:source in documents; X-Git-Tag: 1.7~253 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/fc2ee5e934d0da3535b9be659bbf67ebe9437b47 fixes #938: dc:source in documents; some fixes for titles and atuhor names in pdf --- diff --git a/librarian/dcparser.py b/librarian/dcparser.py index 26f2a0c..00b7cda 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -88,7 +88,7 @@ class Field(object): return val return [ self.validator(v) if v is not None else v for v in val ] elif len(val) > 1: - raise ValidationError("Mulitply values not allowed for field '%s'" % self.uri) + raise ValidationError("Multiple values not allowed for field '%s'" % self.uri) elif len(val) == 0: raise ValidationError("Field %s has no value to assign. Check your defaults." % self.uri) else: diff --git a/librarian/epub/xsltTitle.xsl b/librarian/epub/xsltTitle.xsl index 3b24c76..8f5dfea 100644 --- a/librarian/epub/xsltTitle.xsl +++ b/librarian/epub/xsltTitle.xsl @@ -30,6 +30,7 @@ +

Publikacja zrealizowana w ramach projektu WolneLektury.pl

WolneLektury.pl diff --git a/librarian/functions.py b/librarian/functions.py index 8427ba8..5ad723d 100644 --- a/librarian/functions.py +++ b/librarian/functions.py @@ -6,6 +6,8 @@ from lxml import etree import re +from librarian.dcparser import Person + def _register_function(f): """ Register extension function with lxml """ ns = etree.FunctionNamespace('http://wolnelektury.pl/functions') @@ -68,9 +70,9 @@ def reg_wrap_words(): text = ''.join(text) if not wrapping: return text - + words = re.split(r'\s', text) - + line_length = 0 lines = [[]] for word in words: @@ -89,7 +91,8 @@ def reg_person_name(): """ Converts "Name, Forename" to "Forename Name" """ if isinstance(text, list): text = ''.join(text) - return ' '.join([t.strip() for t in text.split(',', 1)[::-1]]) + p = Person.from_text(text) + return ' '.join(p.first_names + (p.last_name,)) _register_function(person_name) diff --git a/librarian/pdf.py b/librarian/pdf.py index a868a2b..a0a0899 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -19,14 +19,13 @@ from Texml.processor import process from lxml import etree from lxml.etree import XMLSyntaxError, XSLTApplyError +from librarian.dcparser import Person from librarian.parser import WLDocument -from librarian import ParseError +from librarian import ParseError, DCNS from librarian import functions - functions.reg_substitute_entities() -functions.reg_person_name() functions.reg_strip() functions.reg_starts_white() functions.reg_ends_white() @@ -45,27 +44,23 @@ def insert_tags(doc, split_re, tagname): ABCXYZ """ - for elem in doc.iter(): - try: - if elem.text: - chunks = split_re.split(elem.text) - while len(chunks) > 1: - ins = etree.Element(tagname) - ins.tail = chunks.pop() - elem.insert(0, ins) - elem.text = chunks.pop(0) - if elem.tail: - chunks = split_re.split(elem.tail) - parent = elem.getparent() - ins_index = parent.index(elem) + 1 - while len(chunks) > 1: - ins = etree.Element(tagname) - ins.tail = chunks.pop() - parent.insert(ins_index, ins) - elem.tail = chunks.pop(0) - except TypeError, e: - # element with no children, like comment - pass + for elem in doc.iter(tag=etree.Element): + if elem.text: + chunks = split_re.split(elem.text) + while len(chunks) > 1: + ins = etree.Element(tagname) + ins.tail = chunks.pop() + elem.insert(0, ins) + elem.text = chunks.pop(0) + if elem.tail: + chunks = split_re.split(elem.tail) + parent = elem.getparent() + ins_index = parent.index(elem) + 1 + while len(chunks) > 1: + ins = etree.Element(tagname) + ins.tail = chunks.pop() + parent.insert(ins_index, ins) + elem.tail = chunks.pop(0) def substitute_hyphens(doc): @@ -126,6 +121,16 @@ def hack_motifs(doc): break +def parse_creator(doc): + """ find all dc:creator tags and add dc:creator_parsed with forenames first """ + for creator in doc.findall('//'+DCNS('creator')): + p = Person.from_text(creator.text) + creator_parsed = deepcopy(creator) + creator_parsed.tag = DCNS('creator_parsed') + creator_parsed.text = ' '.join(p.first_names + (p.last_name,)) + creator.getparent().insert(0, creator_parsed) + + def get_resource(path): return os.path.join(os.path.dirname(__file__), path) @@ -185,6 +190,7 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir= # hack the tree move_motifs_inside(document.edoc) hack_motifs(document.edoc) + parse_creator(document.edoc) substitute_hyphens(document.edoc) fix_hanging(document.edoc) diff --git a/librarian/pdf/wl.sty b/librarian/pdf/wl.sty index 7a37e28..785b4ce 100644 --- a/librarian/pdf/wl.sty +++ b/librarian/pdf/wl.sty @@ -37,8 +37,6 @@ \clubpenalty=100000 \widowpenalty=100000 -%\interlinepenalty=8000 - \renewcommand{\maketitle}{ { @@ -50,6 +48,10 @@ \includegraphics[width=\textwidth]{wl-logo.png} \end{minipage} \begin{minipage}[t]{.65\textwidth}\vspace{0pt} + \sourceinfo + + \vspace{.5em} + Wejdź na stronę http://wolnelektury.pl/ i~zobacz, jak wiele możliwości daje interaktywna wersja szkolnej biblioteki internetowej Wolne Lektury. \vspace{.5em} diff --git a/librarian/text.py b/librarian/text.py index 57c2a73..a600b71 100644 --- a/librarian/text.py +++ b/librarian/text.py @@ -22,6 +22,8 @@ Publikacja zrealizowana w ramach projektu Wolne Lektury (http://wolnelektury.pl/ Bibliotekę Narodową z egzemplarza pochodzącego ze zbiorów BN. \n%(license_description)s. +%(source)s + Wersja lektury w opracowaniu merytorycznym i krytycznym (przypisy i motywy) dostępna jest na stronie %(url)s. ----- @@ -49,18 +51,21 @@ def transform(input_filename, output_filename, is_file=True, parse_dublincore=Tr parsed_dc = dcparser.parse(input_filename) url = parsed_dc.url license_description = parsed_dc.license_description - license = parsed_dc.license + license = parsed_dc.license if license: license_description = u"Ten utwór jest udostepniony na licencji %s: \n%s" % (license_description, license) else: - license_description = u"Ten utwór nie jest chroniony prawem autorskim i znajduje się w domenie publicznej, co oznacza, że możesz go swobodnie wykorzystywać, publikować i rozpowszechniać" + license_description = u"Ten utwór nie jest chroniony prawem autorskim i znajduje się w domenie publicznej, co oznacza, że możesz go swobodnie wykorzystywać, publikować i rozpowszechniać" + source = parsed_dc.source_name else: url = '*' * 10 license = "" license_description = "" + source = "" output_file.write(TEMPLATE % { 'url': url, - 'license_description': license_description, + 'license_description': license_description, 'text': unicode(result), + 'source': source, }) diff --git a/librarian/xslt/wl2tex.xslt b/librarian/xslt/wl2tex.xslt index e94d4a8..7b5df58 100644 --- a/librarian/xslt/wl2tex.xslt +++ b/librarian/xslt/wl2tex.xslt @@ -85,11 +85,14 @@ - + - + + + \def\sourceinfo{} + @@ -115,10 +118,10 @@ - + - +