cli/search: clear some bugs

This commit is contained in:
Oystein Kristoffer Tveit 2024-05-17 21:40:18 +02:00
parent 77175cbb3a
commit b3f80888d5
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146

View File

@ -13,6 +13,7 @@ class SearchCli(NumberedCmd):
def __init__(self, sql_session: Session):
super().__init__()
self.sql_session = sql_session
self.result = None
def do_search_all(self, _: str):
@ -57,11 +58,11 @@ class SearchCli(NumberedCmd):
elif len(author) == 1:
selected_author = author[0]
print('Found author:')
print(f" {selected_author.name} ({sum(item.amount for item in selected_author.books)} items)")
print(f" {selected_author.name} ({sum(item.amount for item in selected_author.items)} items)")
else:
selector = NumberedItemSelector(
items = author,
stringify = lambda author: f"{author.name} ({sum(item.amount for item in author.books)} items)",
stringify = lambda author: f"{author.name} ({sum(item.amount for item in author.items)} items)",
)
selector.cmdloop()
if selector.result is None:
@ -69,7 +70,7 @@ class SearchCli(NumberedCmd):
selected_author = selector.result
selector = NumberedItemSelector(
items = selected_author.books,
items = list(selected_author.items),
stringify = lambda item: f"{item.name} ({item.isbn})",
)
selector.cmdloop()