From a32b36bf81fcfaf79f16b8d4dc74ee165bf23422 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 30 Jul 2021 16:58:20 +0200 Subject: [PATCH] Fixed missing joins for sorting according to series in read/unread and rated views --- cps/db.py | 4 ++++ cps/web.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cps/db.py b/cps/db.py index ed164afc..71f5031b 100644 --- a/cps/db.py +++ b/cps/db.py @@ -692,6 +692,10 @@ class CalibreDB(): query = self.session.query(database) if len(join) == 6: query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5]) + if len(join) == 5: + query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]) + if len(join) == 4: + query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3]) if len(join) == 3: query = query.outerjoin(join[0], join[1]).outerjoin(join[2]) elif len(join) == 2: diff --git a/cps/web.py b/cps/web.py index ab9c4134..f7291e0a 100644 --- a/cps/web.py +++ b/cps/web.py @@ -423,7 +423,11 @@ def render_rated_books(page, book_id, order): entries, random, pagination = calibre_db.fill_indexpage(page, 0, db.Books, db.Books.ratings.any(db.Ratings.rating > 9), - order) + order, + db.books_series_link, + db.Books.id == db.books_series_link.c.book, + db.Series) + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id, title=_(u"Top Rated Books"), page="rated") else: @@ -629,6 +633,9 @@ def render_read_books(page, are_read, as_xml=False, order=None): db.Books, db_filter, order, + db.books_series_link, + db.Books.id == db.books_series_link.c.book, + db.Series, ub.ReadBook, db.Books.id == ub.ReadBook.book_id) else: try: @@ -640,6 +647,9 @@ def render_read_books(page, are_read, as_xml=False, order=None): db.Books, db_filter, order, + db.books_series_link, + db.Books.id == db.books_series_link.c.book, + db.Series, db.cc_classes[config.config_read_column]) except (KeyError, AttributeError): log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column) @@ -787,7 +797,7 @@ def list_books(): db.books_series_link, db.Books.id == db.books_series_link.c.book, db.Series elif sort == "languages": order = [db.Languages.lang_code.asc()] if order == "asc" else [db.Languages.lang_code.desc()] - join = db.books_languages_link,db.Books.id == db.books_languages_link.c.book, db.Languages + join = db.books_languages_link, db.Books.id == db.books_languages_link.c.book, db.Languages elif order and sort in ["sort", "title", "authors_sort", "series_index"]: order = [text(sort + " " + order)] elif not state: