From d70ded099359a58f4fccae1678bdb12214b5b776 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Sat, 10 Oct 2020 07:47:27 +0200 Subject: [PATCH] Fix for search --- cps/db.py | 8 +++++--- cps/web.py | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cps/db.py b/cps/db.py index 3e0ac195..ca784665 100644 --- a/cps/db.py +++ b/cps/db.py @@ -664,9 +664,6 @@ class CalibreDB(): def get_search_results(self, term, offset=None, order=None, limit=None): order = order or [Books.sort] pagination = None - if offset != None and limit != None: - offset = int(offset) - limit_all = offset + int(limit) term.strip().lower() self.session.connection().connection.connection.create_function("lower", 1, lcase) q = list() @@ -682,7 +679,12 @@ class CalibreDB(): )).order_by(*order).all() result_count = len(result) if offset != None and limit != None: + offset = int(offset) + limit_all = offset + int(limit) pagination = Pagination((offset / (int(limit)) + 1), limit, result_count) + else: + offset = 0 + limit_all = result_count return result[offset:limit_all], result_count, pagination # Creates for all stored languages a translated speaking name in the array for the UI diff --git a/cps/web.py b/cps/web.py index e20759ec..61db9e92 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1248,9 +1248,6 @@ def advanced_search(): def render_adv_search_results(term, offset=None, order=None, limit=None): order = order or [db.Books.sort] pagination = None - if offset != None and limit != None: - offset = int(offset) - limit_all = offset + int(limit) cc = get_cc_columns(filter_config_custom_read=True) calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase) @@ -1391,11 +1388,15 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): # entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit) result_count = len(q) if offset != None and limit != None: + offset = int(offset) + limit_all = offset + int(limit) pagination = Pagination((offset / (int(limit)) + 1), limit, result_count) + else: + offset = 0 + limit_all = result_count return render_title_template('search.html', adv_searchterm=searchterm, pagination=pagination, - # query=request.form, entries=q[offset:limit_all], result_count=result_count, title=_(u"search"), page="advsearch")