mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 18:47:23 +00:00
Merge remote-tracking branch 'origin/Develop' into Develop
This commit is contained in:
commit
df295e92ee
@ -73,7 +73,6 @@ ub.init_db(cli.settingspath)
|
|||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
config = config_sql.load_configuration(ub.session)
|
config = config_sql.load_configuration(ub.session)
|
||||||
|
|
||||||
searched_ids = {}
|
|
||||||
web_server = WebServer()
|
web_server = WebServer()
|
||||||
|
|
||||||
babel = Babel()
|
babel = Babel()
|
||||||
|
@ -543,7 +543,7 @@ class CalibreDB():
|
|||||||
bind=cls.engine))
|
bind=cls.engine))
|
||||||
for inst in cls.instances:
|
for inst in cls.instances:
|
||||||
inst.initSession()
|
inst.initSession()
|
||||||
|
|
||||||
cls._init = True
|
cls._init = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -685,7 +685,11 @@ class CalibreDB():
|
|||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
limit_all = result_count
|
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
|
# Creates for all stored languages a translated speaking name in the array for the UI
|
||||||
def speaking_language(self, languages=None):
|
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.sql.expression import func
|
||||||
from sqlalchemy.exc import OperationalError, InvalidRequestError
|
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
|
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")
|
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'))
|
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_for_shelf = list()
|
||||||
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).all()
|
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).all()
|
||||||
if books_in_shelf:
|
if books_in_shelf:
|
||||||
book_ids = list()
|
book_ids = list()
|
||||||
for book_id in books_in_shelf:
|
for book_id in books_in_shelf:
|
||||||
book_ids.append(book_id.book_id)
|
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:
|
if searchid not in book_ids:
|
||||||
books_for_shelf.append(searchid)
|
books_for_shelf.append(searchid)
|
||||||
else:
|
else:
|
||||||
books_for_shelf = searched_ids[current_user.id]
|
books_for_shelf = ub.searched_ids[current_user.id]
|
||||||
|
|
||||||
if not books_for_shelf:
|
if not books_for_shelf:
|
||||||
log.error("Books are already part of %s", shelf)
|
log.error("Books are already part of %s", shelf)
|
||||||
|
10
cps/ub.py
10
cps/ub.py
@ -28,7 +28,7 @@ from binascii import hexlify
|
|||||||
|
|
||||||
from flask import g
|
from flask import g
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from flask_login import AnonymousUserMixin
|
from flask_login import AnonymousUserMixin, current_user
|
||||||
from werkzeug.local import LocalProxy
|
from werkzeug.local import LocalProxy
|
||||||
try:
|
try:
|
||||||
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
|
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
|
||||||
@ -54,6 +54,7 @@ from . import constants
|
|||||||
session = None
|
session = None
|
||||||
app_DB_path = None
|
app_DB_path = None
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
searched_ids = {}
|
||||||
|
|
||||||
|
|
||||||
def get_sidebar_config(kwargs=None):
|
def get_sidebar_config(kwargs=None):
|
||||||
@ -123,6 +124,13 @@ def get_sidebar_config(kwargs=None):
|
|||||||
return sidebar
|
return sidebar
|
||||||
|
|
||||||
|
|
||||||
|
def store_ids(result):
|
||||||
|
ids = list()
|
||||||
|
for element in result:
|
||||||
|
ids.append(element.id)
|
||||||
|
searched_ids[current_user.id] = ids
|
||||||
|
|
||||||
|
|
||||||
class UserBase:
|
class UserBase:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
13
cps/web.py
13
cps/web.py
@ -54,7 +54,7 @@ from werkzeug.datastructures import Headers
|
|||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
from . import constants, logger, isoLanguages, services
|
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 . import calibre_db
|
||||||
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
||||||
from .helper import check_valid_domain, render_task_status, \
|
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):
|
def render_search_results(term, offset=None, order=None, limit=None):
|
||||||
entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
|
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',
|
return render_title_template('search.html',
|
||||||
searchterm=term,
|
searchterm=term,
|
||||||
pagination=pagination,
|
pagination=pagination,
|
||||||
@ -1239,6 +1235,7 @@ def search():
|
|||||||
title=_(u"Search"),
|
title=_(u"Search"),
|
||||||
page="search")
|
page="search")
|
||||||
|
|
||||||
|
|
||||||
@web.route("/advanced_search", methods=['POST'])
|
@web.route("/advanced_search", methods=['POST'])
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def advanced_search():
|
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 + "%")))
|
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
|
||||||
q = q.order_by(*order).all()
|
q = q.order_by(*order).all()
|
||||||
flask_session['query'] = json.dumps(term)
|
flask_session['query'] = json.dumps(term)
|
||||||
# ToDo: Check saved ids mechanism ?
|
ub.store_ids(q)
|
||||||
ids = list()
|
|
||||||
for element in q:
|
|
||||||
ids.append(element.id)
|
|
||||||
searched_ids[current_user.id] = ids
|
|
||||||
# entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
|
# entries, result_count, pagination = calibre_db.get_search_results(term, offset, order, limit)
|
||||||
result_count = len(q)
|
result_count = len(q)
|
||||||
if offset != None and limit != None:
|
if offset != None and limit != None:
|
||||||
|
Loading…
Reference in New Issue
Block a user