|
@ -1,5 +1,7 @@ |
|
|
"""Generates PDF cards from a calibre metadata.db.""" |
|
|
"""Generates PDF cards from a calibre metadata.db.""" |
|
|
|
|
|
|
|
|
|
|
|
from textwrap import shorten |
|
|
|
|
|
|
|
|
from calibrestekje import Book, Comment, Publisher, init_session |
|
|
from calibrestekje import Book, Comment, Publisher, init_session |
|
|
from reportlab.lib.pagesizes import * |
|
|
from reportlab.lib.pagesizes import * |
|
|
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet |
|
|
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet |
|
@ -21,44 +23,48 @@ def get_fields(db_path, fields): |
|
|
session = init_session(db_path) |
|
|
session = init_session(db_path) |
|
|
|
|
|
|
|
|
for book in session.query(Book).all(): |
|
|
for book in session.query(Book).all(): |
|
|
for comment in session.query(Comment).all(): |
|
|
if "title" in fields: |
|
|
|
|
|
tag = "<font size=12>{}</font>".format(book.title) |
|
|
if "title" in fields: |
|
|
ptitle = Paragraph(tag, styles["Italic"]) |
|
|
tag = "<font size=12>{}</font>".format(book.title) |
|
|
content.append(ptitle) |
|
|
ptitle = Paragraph(tag, styles["Italic"]) |
|
|
content.append(Spacer(1, 12)) |
|
|
content.append(ptitle) |
|
|
|
|
|
content.append(Spacer(1, 12)) |
|
|
if "uploaded_at" in fields: |
|
|
|
|
|
tag = "<font size=10>Uploaded: {}</font>".format(book.timestamp) |
|
|
if "uploaded_at" in fields: |
|
|
ptime = Paragraph(tag, styles["Normal"]) |
|
|
tag = "<font size=10>Uploaded: {}</font>".format(book.timestamp) |
|
|
content.append(ptime) |
|
|
ptime = Paragraph(tag, styles["Normal"]) |
|
|
content.append(Spacer(1, 12)) |
|
|
content.append(ptime) |
|
|
|
|
|
content.append(Spacer(1, 12)) |
|
|
if "comments" in fields: |
|
|
|
|
|
comments = ", ".join( |
|
|
if "comments" in fields: |
|
|
[ |
|
|
tag = "<font size=10>{}</font>".format(comment.text) |
|
|
shorten(comment.text, width=50, placeholder="...") |
|
|
pcomments = Paragraph(tag) |
|
|
for comment in book.comments |
|
|
content.append(pcomments) |
|
|
] |
|
|
|
|
|
) |
|
|
if "authors" in fields: |
|
|
tag = "<font size=10>{}</font>".format(comments) |
|
|
format_string = "<font size=12>{}</font>" |
|
|
pcomments = Paragraph(tag) |
|
|
all_authors = [author.name for author in book.authors] |
|
|
content.append(pcomments) |
|
|
glued_together = format_string.format(", ".join(all_authors)) |
|
|
|
|
|
|
|
|
if "authors" in fields: |
|
|
p = Paragraph(glued_together, styles["Normal"]) |
|
|
format_string = "<font size=12>{}</font>" |
|
|
content.append(p) |
|
|
all_authors = [author.name for author in book.authors] |
|
|
content.append(PageBreak()) |
|
|
glued_together = format_string.format(", ".join(all_authors)) |
|
|
content.append(Spacer(6, 12)) |
|
|
|
|
|
|
|
|
p = Paragraph(glued_together, styles["Normal"]) |
|
|
if "tags" in fields: |
|
|
content.append(p) |
|
|
format_string = "<font size=10>{}</font>" |
|
|
content.append(PageBreak()) |
|
|
all_tags = [tag.name for tag in book.tags] |
|
|
content.append(Spacer(6, 12)) |
|
|
tags_glued_together = format_string.format(", ".join(all_tags)) |
|
|
|
|
|
|
|
|
if "tags" in fields: |
|
|
p = Paragraph(tags_glued_together, styles["Normal"]) |
|
|
format_string = "<font size=10>{}</font>" |
|
|
content.append(p) |
|
|
all_tags = [tag.name for tag in book.tags] |
|
|
content.append(PageBreak()) |
|
|
tags_glued_together = format_string.format(", ".join(all_tags)) |
|
|
content.append(Spacer(6, 12)) |
|
|
|
|
|
|
|
|
p = Paragraph(tags_glued_together, styles["Normal"]) |
|
|
|
|
|
content.append(p) |
|
|
|
|
|
content.append(PageBreak()) |
|
|
|
|
|
content.append(Spacer(6, 12)) |
|
|
|
|
|
|
|
|
return content |
|
|
return content |
|
|
|
|
|
|
|
|