handle missing tags
This commit is contained in:
parent
a3444bea9d
commit
ad250d011d
@ -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…
Reference in New Issue
Block a user