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. 12
      temp_index.py

12
temp_index.py

@ -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,8 +23,6 @@ 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: if "title" in fields:
tag = "<font size=12>{}</font>".format(book.title) tag = "<font size=12>{}</font>".format(book.title)
ptitle = Paragraph(tag, styles["Italic"]) ptitle = Paragraph(tag, styles["Italic"])
@ -36,7 +36,13 @@ def get_fields(db_path, fields):
content.append(Spacer(1, 12)) content.append(Spacer(1, 12))
if "comments" in fields: if "comments" in fields:
tag = "<font size=10>{}</font>".format(comment.text) comments = ", ".join(
[
shorten(comment.text, width=50, placeholder="...")
for comment in book.comments
]
)
tag = "<font size=10>{}</font>".format(comments)
pcomments = Paragraph(tag) pcomments = Paragraph(tag)
content.append(pcomments) content.append(pcomments)

Loading…
Cancel
Save