From 8ad84a7cebb0827cfe827524bee38536ff933410 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Thu, 2 Jan 2020 17:11:30 +0100 Subject: [PATCH] Fix for #1123 (mature content is visible in shelfs) --- cps/shelf.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cps/shelf.py b/cps/shelf.py index 0440a87b..1d24c4f1 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -30,6 +30,7 @@ from sqlalchemy.sql.expression import func, or_, and_ from . import logger, ub, searched_ids, db from .web import render_title_template +from .helper import common_filters shelf = Blueprint('shelf', __name__) @@ -281,16 +282,10 @@ def show_shelf(shelf_type, shelf_id): if shelf: page = "shelf.html" if shelf_type == 1 else 'shelfdown.html' - books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by( - ub.BookShelf.order.asc()).all() - for book in books_in_shelf: - cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first() - if cur_book: - result.append(cur_book) - else: - log.info('Not existing book %s in %s deleted', book.book_id, shelf) - ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete() - ub.session.commit() + books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id)\ + .order_by(ub.BookShelf.order.asc()).all() + books_list = [ b.book_id for b in books_in_shelf] + result = db.session.query(db.Books).filter(db.Books.id.in_(books_list)).filter(common_filters()).all() return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), shelf=shelf, page="shelf") else: @@ -322,9 +317,8 @@ def order_shelf(shelf_id): if shelf: books_in_shelf2 = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id) \ .order_by(ub.BookShelf.order.asc()).all() - for book in books_in_shelf2: - cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first() - result.append(cur_book) + books_list = [ b.book_id for b in books_in_shelf2] + result = db.session.query(db.Books).filter(db.Books.id.in_(books_list)).filter(common_filters()).all() return render_title_template('shelf_order.html', entries=result, title=_(u"Change order of Shelf: '%(name)s'", name=shelf.name), shelf=shelf, page="shelforder")