From beca61a59667f1669380f7075f42804b286eae7e Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Tue, 10 Jan 2017 21:20:12 +0100 Subject: [PATCH] Nonexisting books are deleted from downloaded list (#91) --- cps/web.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cps/web.py b/cps/web.py index 160a57f1..2ff149e4 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1433,7 +1433,12 @@ def profile(): lang.name = _(isoLanguages.get(part3=lang.lang_code).name) translations = babel.list_translations() + [LC('en')] for book in content.downloads: - downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) + downloadBook=db.session.query(db.Books).filter(db.Books.id == book.book_id).first() + if downloadBook: + downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) + else: + ub.session.query(ub.Downloads).filter(book.book_id == ub.Downloads.book_id).delete() + ub.session.commit() if request.method == "POST": to_save = request.form.to_dict() content.random_books = 0 @@ -1601,7 +1606,12 @@ def edit_user(user_id): lang.name = _(isoLanguages.get(part3=lang.lang_code).name) translations = babel.list_translations() + [LC('en')] for book in content.downloads: - downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) + downloadBook=db.session.query(db.Books).filter(db.Books.id == book.book_id).first() + if downloadBook: + downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) + else: + ub.session.query(ub.Downloads).filter(book.book_id == ub.Downloads.book_id).delete() + ub.session.commit() if request.method == "POST": to_save = request.form.to_dict() if "delete" in to_save: