From 4332f7a640792857a21e982e23fe4c57758763bf Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 17 May 2020 21:44:12 +0200 Subject: [PATCH 1/4] Better detection of localhost for kobo sync (possibly related to #1400) --- cps/kobo_auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cps/kobo_auth.py b/cps/kobo_auth.py index 7fa778cd..0f6cd174 100644 --- a/cps/kobo_auth.py +++ b/cps/kobo_auth.py @@ -121,7 +121,11 @@ kobo_auth = Blueprint("kobo_auth", __name__, url_prefix="/kobo_auth") @kobo_auth.route("/generate_auth_token/") @login_required def generate_auth_token(user_id): - host = ':'.join(request.host.rsplit(':')[0:-1]) + host_list = request.host.rsplit(':') + if len(host_list) == 1: + host = ':'.join(host_list) + else: + host = ':'.join(host_list[0:-1]) if host.startswith('127.') or host.lower() == 'localhost' or host.startswith('[::ffff:7f'): warning = _('PLease access calibre-web from non localhost to get valid api_endpoint for kobo device') return render_title_template( From 29b94c561541b46092396740028cd84ae6ec3d2d Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Tue, 19 May 2020 21:36:22 +0200 Subject: [PATCH 2/4] Fix for #1407 (to many read books lead to to large sql query) -> only fix for linked calibre-column --- cps/helper.py | 10 +++++----- cps/web.py | 31 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index d369a6d0..7858633a 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -824,12 +824,12 @@ def fill_indexpage_with_archived_books(page, database, db_filter, order, allow_s else: randm = false() off = int(int(config.config_books_per_page) * (page - 1)) + query = db.session.query(database).join(*join, isouter=True).\ + filter(db_filter).\ + filter(common_filters(allow_show_archived)) pagination = Pagination(page, config.config_books_per_page, - len(db.session.query(database).filter(db_filter) - .filter(common_filters(allow_show_archived)).all())) - entries = db.session.query(database).join(*join, isouter=True).filter(db_filter)\ - .filter(common_filters(allow_show_archived))\ - .order_by(*order).offset(off).limit(config.config_books_per_page).all() + len(query.all())) + entries = query.order_by(*order).offset(off).limit(config.config_books_per_page).all() for book in entries: book = order_authors(book) return entries, randm, pagination diff --git a/cps/web.py b/cps/web.py index 3da3e799..5529aea8 100644 --- a/cps/web.py +++ b/cps/web.py @@ -40,6 +40,7 @@ from flask_login import login_user, logout_user, login_required, current_user from sqlalchemy.exc import IntegrityError from sqlalchemy.sql.expression import text, func, true, false, not_, and_, or_ from werkzeug.exceptions import default_exceptions +from sqlalchemy.sql.functions import coalesce try: from werkzeug.exceptions import FailedDependency except ImportError: @@ -1102,31 +1103,35 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs) readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id))\ .filter(ub.ReadBook.read_status == ub.ReadBook.STATUS_FINISHED).all() readBookIds = [x.book_id for x in readBooks] + if are_read: + db_filter = db.Books.id.in_(readBookIds) + else: + db_filter = ~db.Books.id.in_(readBookIds) + entries, random, pagination = fill_indexpage(page, db.Books, db_filter, order) else: try: - readBooks = db.session.query(db.cc_classes[config.config_read_column]) \ - .filter(db.cc_classes[config.config_read_column].value == True).all() - readBookIds = [x.book for x in readBooks] + if are_read: + db_filter = db.cc_classes[config.config_read_column].value == True + else: + db_filter = coalesce(db.cc_classes[config.config_read_column].value, False) != True + # book_count = db.session.query(func.count(db.Books.id)).filter(common_filters()).filter(db_filter).scalar() + entries, random, pagination = fill_indexpage(page, db.Books, + db_filter, + order, + db.cc_classes[config.config_read_column]) except KeyError: log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column) - readBookIds = [] - - if are_read: - db_filter = db.Books.id.in_(readBookIds) - else: - db_filter = ~db.Books.id.in_(readBookIds) + book_count = 0 - entries, random, pagination = fill_indexpage(page, db.Books, db_filter, order) if as_xml: return entries, pagination else: if are_read: - name = _(u'Read Books') + ' (' + str(len(readBookIds)) + ')' + name = _(u'Read Books') + ' (' + str(pagination.total_count) + ')' pagename = "read" else: - total_books = db.session.query(func.count(db.Books.id)).filter(common_filters()).scalar() - name = _(u'Unread Books') + ' (' + str(total_books - len(readBookIds)) + ')' + name = _(u'Unread Books') + ' (' + str(pagination.total_count) + ')' pagename = "unread" return render_title_template('index.html', random=random, entries=entries, pagination=pagination, title=name, page=pagename) From 051ffdda35fe2dc8f74114a4de6ce69909412939 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Thu, 21 May 2020 16:42:02 +0200 Subject: [PATCH 3/4] activate search focus if search in progress --- cps/templates/layout.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cps/templates/layout.html b/cps/templates/layout.html index d486e103..95eecf80 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -227,7 +227,9 @@ $(document).ready(function() { var inp = $('#query').first() var val = inp.val() - inp.val('').blur().focus().val(val) + if (val.length) { + inp.val('').blur().focus().val(val) + } }); }); From 098dab889a3997543a94713364802172fece13c1 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Thu, 21 May 2020 19:37:54 +0200 Subject: [PATCH 4/4] Fixed title sorting routine --- cps/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/db.py b/cps/db.py index 499765d1..6d31e599 100755 --- a/cps/db.py +++ b/cps/db.py @@ -318,7 +318,7 @@ def update_title_sort(config, conn=None): match = title_pat.search(title) if match: prep = match.group(1) - title = title.replace(prep, '') + ', ' + prep + title = title[len(prep):] + ', ' + prep return title.strip() conn = conn or session.connection().connection.connection