Browse Source

fix comment handling

main
cellarspoon 3 years ago
parent
commit
216c7e110d
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 82
      temp_index.py

82
temp_index.py

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

Loading…
Cancel
Save