Browse Source

handle missing tags

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

14
temp_index.py

@ -52,6 +52,8 @@ def make_cards(filepath, db_path, side_a, side_b):
def select_fields(fields, content, styles, book):
appended = True
if "title" in fields:
tag = "<font size=12>{}</font>".format(strip_tags(book.title))
ptitle = Paragraph(tag, styles["Italic"])
@ -87,13 +89,14 @@ def select_fields(fields, content, styles, book):
if "tags" in fields:
format_string = "<font size=10>{}</font>"
all_tags = [strip_tags(tag.name) for tag in book.tags]
if not all_tags:
appended = False
tags_glued_together = format_string.format(", ".join(all_tags))
p = Paragraph(tags_glued_together, styles["Normal"])
content.append(p)
content.append(Spacer(6, 12))
return content
return content, appended
def get_fields(db_path, side_a, side_b):
@ -103,10 +106,11 @@ def get_fields(db_path, side_a, side_b):
session = init_session(db_path)
for book in session.query(Book).all():
content = select_fields(side_a, content, styles, book)
content.append(PageBreak())
content = select_fields(side_b, content, styles, book)
content, _ = select_fields(side_a, content, styles, book)
content.append(PageBreak())
content, appended = select_fields(side_b, content, styles, book)
if appended:
content.append(PageBreak())
return content

Loading…
Cancel
Save