From 8ad84a7cebb0827cfe827524bee38536ff933410 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Thu, 2 Jan 2020 17:11:30 +0100 Subject: [PATCH 1/2] 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") From 56ee8c56baf2aade7fac95ba3ae29d472f49b1f7 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 5 Jan 2020 08:40:57 +0100 Subject: [PATCH 2/2] Fix #1122 (Uploading books with applied language restriction leads no longer to error 500) --- cps/editbooks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 91134db6..7b78cf97 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -656,10 +656,16 @@ def upload(): db_language = db.Languages(input_language) db.session.add(db_language) + # If the language of the file is excluded from the users view, it's not imported, to allow the user to view + # the book it's language is set to the filter language + if db_language != current_user.filter_language() and current_user.filter_language() != "all": + db_language = db.session.query(db.Languages).\ + filter(db.Languages.lang_code == current_user.filter_language()).first() + # combine path and normalize path from windows systems path = os.path.join(author_dir, title_dir).replace('\\', '/') db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1), - series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language) + series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language) db_book.authors.append(db_author) if db_series: db_book.series.append(db_series) @@ -688,7 +694,9 @@ def upload(): # save data to database, reread data db.session.commit() db.update_title_sort(config) - book = db.session.query(db.Books).filter(db.Books.id == book_id).filter(common_filters()).first() + # Reread book. It's important not to filter the result, as it could have language which hide it from + # current users view (tags are not stored/extracted from metadata and could also be limited) + book = db.session.query(db.Books).filter(db.Books.id == book_id).first() # upload book to gdrive if nesseccary and add "(bookid)" to folder name if config.config_use_google_drive: