remove loaned books from books on shelf - fixes BUG-38

This commit is contained in:
2023-07-05 20:00:28 +10:00
parent 8957771ae1
commit 0803c3cf22
2 changed files with 12 additions and 2 deletions

12
main.py
View File

@@ -951,12 +951,24 @@ def OrderBooks(books):
ordered_books.append(b)
return ordered_books
def RemLoans(books):
""" Remove any books on loan from list - used for books on shelf view """
from main import Book_Loan_Link
loaned_books=Book_Loan_Link.query.all()
for b in loaned_books:
for i, item in enumerate(books):
if item.id == b.book_id:
books.remove(item)
@app.route("/books_on_shelf", methods=["GET"])
@login_required
def books_on_shelf():
# start with all books owned sorted by author, then title, but it includes sub-books, so remove them...
books = Book.query.join(Owned).join(Book_Author_Link).join(Author).filter(Owned.name=='Currently Owned').filter(Book_Author_Link.author_num==1).order_by(Author.surname,Author.firstnames,Book.title).all()
RemLoans(books)
RemSubs(books)
ordered_books=OrderBooks(books)