Changeset - f5ed6b020878
[Not reviewed]
default
0 1 0
Dennis Fink - 3 years ago 2022-03-21 20:55:40
dennis.fink@c3l.lu
Don't fail if the book has not isbn
1 file changed with 4 insertions and 0 deletions:
0 comments (0 inline, 0 general)
stockcli/books.py
Show inline comments
 
@@ -19,24 +19,28 @@ def add_book_by_barcode(barcode: str) ->
 

	
 
    userentity = utils.get_request("objects/userentities?query[]=name=books")
 
    userentity_id = userentity[0]["id"]
 

	
 
    all_books = utils.get_request(
 
        f"objects/userobjects?query[]=userentity_id={userentity_id}"
 
    )
 

	
 
    for book in all_books:
 
        book_metadata = utils.get_request(
 
            f"userfields/userentity-books/{book['id']}", cached=True
 
        )
 

	
 
        if book_metadata["isbn"] is None:
 
            continue
 

	
 
        if isbnlib.canonical(book_metadata["isbn"]) == canonical_isbn:
 

	
 
            book_metadata = utils.get_request(
 
                f"userfields/userentity-books/{book['id']}", cached=False
 
            )
 

	
 
            grid = Table.grid(padding=DEFAULT_PADDING)
 
            grid.add_column(justify="right", no_wrap=True)
 
            grid.add_column(justify="left", style="cyan", no_wrap=True)
 
            grid.add_row(GreenBoldText("Title:"), book_metadata["title"])
 
            grid.add_row(GreenBoldText("Amount:"), book_metadata["amount"])
 
            console.print(
0 comments (0 inline, 0 general)