2 from librarian import RDFNS, DCNS
4 from datetime import date
6 from django.conf import settings
9 def build_document_texts(book):
11 for builder in text_builders:
12 root = etree.Element('utwor')
17 master = etree.SubElement(root, 'powiesc')
19 for book_source in book.booksource_set.all():
20 for page in book_source.get_ocr_files():
23 texts.append(etree.tostring(root, encoding='unicode', pretty_print=True))
28 ocr.add_page_to_master,
29 ocr.add_page_to_master_as_stanzas,
30 ocr.add_page_to_master_as_p,
34 def add_rdf(root, book):
36 rdf = etree.SubElement(root, RDFNS('RDF'))
37 desc = etree.SubElement(rdf, RDFNS('Description'), **{})
40 for author in book.authors.all():
41 etree.SubElement(desc, DCNS('creator')).text = f'{author.last_name_pl}, {author.first_name_pl}'
43 for tr in book.translators.all():
44 etree.SubElement(desc, DCNS('contributor.translator')).text = f'{tr.last_name_pl}, {tr.first_name_pl}'
46 etree.SubElement(desc, DCNS('title')).text = book.title
48 etree.SubElement(desc, DCNS('date')).text = date.today().isoformat()
50 etree.SubElement(desc, DCNS('date.pd')).text = str(book.pd_year)
52 etree.SubElement(desc, DCNS('publisher')). text = 'Fundacja Wolne Lektury'
54 etree.SubElement(desc, DCNS('language')).text = book.language # 3to2?
57 # TODO: allow multiple source meta entries.
59 for book_source in book.booksource_set.all():
60 sources.append(book_source.source.name)
61 etree.SubElement(desc, DCNS('source')).text = ';\n '.join(sources)
63 etree.SubElement(desc, DCNS('identifier.url')).text = f'https://wolnelektury.pl/katalog/lektura/{book.slug}/'
66 etree.SubElement(desc, DCNS('rights')).text = ''
68 for tag in book.epochs.all():
69 etree.SubElement(desc, DCNS('subject.period')).text = tag.name
71 for tag in book.kinds.all():
72 etree.SubElement(desc, DCNS('subject.type')).text = tag.name
74 for tag in book.genres.all():
75 etree.SubElement(desc, DCNS('subject.genre')).text = tag.name