Fix add to shelf from search

pull/1539/merge
Ozzieisaacs 4 years ago
parent d70ded0993
commit 2e67bd2407

@ -73,7 +73,6 @@ ub.init_db(cli.settingspath)
# pylint: disable=no-member
config = config_sql.load_configuration(ub.session)
searched_ids = {}
web_server = WebServer()
babel = Babel()

@ -543,7 +543,7 @@ class CalibreDB():
bind=cls.engine))
for inst in cls.instances:
inst.initSession()
cls._init = True
return True
@ -685,7 +685,11 @@ class CalibreDB():
else:
offset = 0
limit_all = result_count
return result[offset:limit_all], result_count, pagination
ub.store_ids(result)
return result[offset:limit_all], result_count, pagination,
# Creates for all stored languages a translated speaking name in the array for the UI
def speaking_language(self, languages=None):

@ -29,7 +29,7 @@ from flask_login import login_required, current_user
from sqlalchemy.sql.expression import func
from sqlalchemy.exc import OperationalError, InvalidRequestError
from . import logger, ub, searched_ids, calibre_db
from . import logger, ub, calibre_db
from .web import login_required_if_no_ano, render_title_template
@ -124,18 +124,18 @@ def search_to_shelf(shelf_id):
flash(_(u"You are not allowed to add a book to the the shelf: %(name)s", name=shelf.name), category="error")
return redirect(url_for('web.index'))
if current_user.id in searched_ids and searched_ids[current_user.id]:
if current_user.id in ub.searched_ids and ub.searched_ids[current_user.id]:
books_for_shelf = list()
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).all()
if books_in_shelf:
book_ids = list()
for book_id in books_in_shelf:
book_ids.append(book_id.book_id)
for searchid in searched_ids[current_user.id]:
for searchid in ub.searched_ids[current_user.id]:
if searchid not in book_ids:
books_for_shelf.append(searchid)
else:
books_for_shelf = searched_ids[current_user.id]
books_for_shelf = ub.searched_ids[current_user.id]
if not books_for_shelf:
log.error("Books are already part of %s", shelf)

@ -28,7 +28,7 @@ from binascii import hexlify
from flask import g
from flask_babel import gettext as _
from flask_login import AnonymousUserMixin
from flask_login import AnonymousUserMixin, current_user
from werkzeug.local import LocalProxy
try:
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
@ -54,6 +54,7 @@ from . import constants
session = None
app_DB_path = None
Base = declarative_base()
searched_ids = {}
def get_sidebar_config(kwargs=None):
@ -123,6 +124,13 @@ def get_sidebar_config(kwargs=None):
return sidebar
def store_ids(result):
ids = list()
for element in result:
ids.append(element.id)
searched_ids[current_user.id] = ids
class UserBase:
@property

@ -54,7 +54,7 @@ from werkzeug.datastructures import Headers
from werkzeug.security import generate_password_hash, check_password_hash
from . import constants, logger, isoLanguages, services
from . import searched_ids, lm, babel, db, ub, config, get_locale, app
from . import lm, babel, db, ub, config, get_locale, app
from . import calibre_db
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
from .helper import check_valid_domain, render_task_status, \
@ -956,10 +956,6 @@ def render_prepare_search_form(cc):
def render_search_results(term, offset=None, order=None, limit=None):
entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
ids = list()
for element in entries:
ids.append(element.id)
searched_ids[current_user.id] = ids
return render_title_template('search.html',
searchterm=term,
pagination=pagination,
@ -1239,6 +1235,7 @@ def search():
title=_(u"Search"),
page="search")
@web.route("/advanced_search", methods=['POST'])
@login_required_if_no_ano
def advanced_search():
@ -1380,11 +1377,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
q = q.order_by(*order).all()
flask_session['query'] = json.dumps(term)
# ToDo: Check saved ids mechanism ?
ids = list()
for element in q:
ids.append(element.id)
searched_ids[current_user.id] = ids
ub.store_ids(q)
# entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
result_count = len(q)
if offset != None and limit != None:

Loading…
Cancel
Save