Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
d2510ad1bc
80
cps/web.py
80
cps/web.py
|
@ -1231,7 +1231,9 @@ def reconnect():
|
||||||
def search():
|
def search():
|
||||||
term = request.args.get("query")
|
term = request.args.get("query")
|
||||||
if term:
|
if term:
|
||||||
return render_search_results(term, 0, None, config.config_books_per_page)
|
# flask_session['query'] = json.dumps(request.form)
|
||||||
|
return redirect(url_for('web.books_list', data="search", sort_param='stored', query=term))
|
||||||
|
# return render_search_results(term, 0, None, config.config_books_per_page)
|
||||||
else:
|
else:
|
||||||
return render_title_template('search.html',
|
return render_title_template('search.html',
|
||||||
searchterm="",
|
searchterm="",
|
||||||
|
@ -1240,11 +1242,17 @@ def search():
|
||||||
page="search")
|
page="search")
|
||||||
|
|
||||||
|
|
||||||
@web.route("/advanced_search", methods=['POST'])
|
@web.route("/advsearch", methods=['POST'])
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def advanced_search():
|
def advanced_search():
|
||||||
term = request.form
|
values = dict(request.form)
|
||||||
return render_adv_search_results(term, 0, None, config.config_books_per_page)
|
params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_language',
|
||||||
|
'exclude_language', 'include_extension', 'exclude_extension']
|
||||||
|
for param in params:
|
||||||
|
values[param] = list(request.form.getlist(param))
|
||||||
|
flask_session['query'] = json.dumps(values)
|
||||||
|
return redirect(url_for('web.books_list', data="advsearch", sort_param='stored', query=""))
|
||||||
|
|
||||||
|
|
||||||
def render_adv_search_results(term, offset=None, order=None, limit=None):
|
def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
order = order or [db.Books.sort]
|
order = order or [db.Books.sort]
|
||||||
|
@ -1254,14 +1262,14 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
|
calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
|
||||||
q = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(True))
|
q = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(True))
|
||||||
|
|
||||||
include_tag_inputs = request.form.getlist('include_tag')
|
include_tag_inputs = term.get('include_tag')
|
||||||
exclude_tag_inputs = request.form.getlist('exclude_tag')
|
exclude_tag_inputs = term.get('exclude_tag')
|
||||||
include_series_inputs = request.form.getlist('include_serie')
|
include_series_inputs = term.get('include_serie')
|
||||||
exclude_series_inputs = request.form.getlist('exclude_serie')
|
exclude_series_inputs = term.get('exclude_serie')
|
||||||
include_languages_inputs = request.form.getlist('include_language')
|
include_languages_inputs = term.get('include_language')
|
||||||
exclude_languages_inputs = request.form.getlist('exclude_language')
|
exclude_languages_inputs = term.get('exclude_language')
|
||||||
include_extension_inputs = request.form.getlist('include_extension')
|
include_extension_inputs = term.get('include_extension')
|
||||||
exclude_extension_inputs = request.form.getlist('exclude_extension')
|
exclude_extension_inputs = term.get('exclude_extension')
|
||||||
|
|
||||||
author_name = term.get("author_name")
|
author_name = term.get("author_name")
|
||||||
book_title = term.get("book_title")
|
book_title = term.get("book_title")
|
||||||
|
@ -1281,15 +1289,14 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
searchterm = []
|
searchterm = []
|
||||||
cc_present = False
|
cc_present = False
|
||||||
for c in cc:
|
for c in cc:
|
||||||
if request.form.get('custom_column_' + str(c.id)):
|
if term.get('custom_column_' + str(c.id)):
|
||||||
searchterm.extend([(u"%s: %s" % (c.name, request.form.get('custom_column_' + str(c.id))))])
|
searchterm.extend([(u"%s: %s" % (c.name, term.get('custom_column_' + str(c.id))))])
|
||||||
cc_present = True
|
cc_present = True
|
||||||
|
|
||||||
if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \
|
if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \
|
||||||
include_languages_inputs or exclude_languages_inputs or author_name or book_title or \
|
include_languages_inputs or exclude_languages_inputs or author_name or book_title or \
|
||||||
publisher or pub_start or pub_end or rating_low or rating_high or description or cc_present or \
|
publisher or pub_start or pub_end or rating_low or rating_high or description or cc_present or \
|
||||||
include_extension_inputs or exclude_extension_inputs:
|
include_extension_inputs or exclude_extension_inputs:
|
||||||
searchterm = []
|
|
||||||
searchterm.extend((author_name.replace('|', ','), book_title, publisher))
|
searchterm.extend((author_name.replace('|', ','), book_title, publisher))
|
||||||
if pub_start:
|
if pub_start:
|
||||||
try:
|
try:
|
||||||
|
@ -1309,7 +1316,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
searchterm.extend(tag.name for tag in tag_names)
|
searchterm.extend(tag.name for tag in tag_names)
|
||||||
serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
||||||
searchterm.extend(serie.name for serie in serie_names)
|
searchterm.extend(serie.name for serie in serie_names)
|
||||||
language_names = calibre_db.session.query(db.Languages).filter(db.Languages.id.in_(include_languages_inputs)).all()
|
language_names = calibre_db.session.query(db.Languages).\
|
||||||
|
filter(db.Languages.id.in_(include_languages_inputs)).all()
|
||||||
if language_names:
|
if language_names:
|
||||||
language_names = calibre_db.speaking_language(language_names)
|
language_names = calibre_db.speaking_language(language_names)
|
||||||
searchterm.extend(language.name for language in language_names)
|
searchterm.extend(language.name for language in language_names)
|
||||||
|
@ -1320,9 +1328,9 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
searchterm.extend(ext for ext in include_extension_inputs)
|
searchterm.extend(ext for ext in include_extension_inputs)
|
||||||
searchterm.extend(ext for ext in exclude_extension_inputs)
|
searchterm.extend(ext for ext in exclude_extension_inputs)
|
||||||
# handle custom columns
|
# handle custom columns
|
||||||
for c in cc:
|
#for c in cc:
|
||||||
if request.form.get('custom_column_' + str(c.id)):
|
# if term.get('custom_column_' + str(c.id)):
|
||||||
searchterm.extend([(u"%s: %s" % (c.name, request.form.get('custom_column_' + str(c.id))))])
|
# searchterm.extend([(u"%s: %s" % (c.name, term.get('custom_column_' + str(c.id))))])
|
||||||
searchterm = " + ".join(filter(None, searchterm))
|
searchterm = " + ".join(filter(None, searchterm))
|
||||||
q = q.filter()
|
q = q.filter()
|
||||||
if author_name:
|
if author_name:
|
||||||
|
@ -1365,7 +1373,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
|
|
||||||
# search custom culumns
|
# search custom culumns
|
||||||
for c in cc:
|
for c in cc:
|
||||||
custom_query = request.form.get('custom_column_' + str(c.id))
|
custom_query = term.get('custom_column_' + str(c.id))
|
||||||
if custom_query != '' and custom_query is not None:
|
if custom_query != '' and custom_query is not None:
|
||||||
if c.datatype == 'bool':
|
if c.datatype == 'bool':
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
|
@ -1379,18 +1387,18 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
else:
|
else:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
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)
|
||||||
ub.store_ids(q)
|
ub.store_ids(q)
|
||||||
# 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:
|
||||||
offset = int(offset)
|
offset = int(offset)
|
||||||
limit_all = offset + int(limit)
|
limit_all = offset + int(limit)
|
||||||
pagination = Pagination((offset / (int(limit)) + 1), limit, result_count)
|
pagination = Pagination((offset / (int(limit)) + 1), limit, result_count)
|
||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
limit_all = result_count
|
limit_all = result_count
|
||||||
return render_title_template('search.html',
|
return render_title_template('search.html',
|
||||||
adv_searchterm=searchterm,
|
adv_searchterm=searchterm,
|
||||||
pagination=pagination,
|
pagination=pagination,
|
||||||
|
@ -1400,7 +1408,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@web.route("/advanced_search", methods=['GET'])
|
@web.route("/advsearch", methods=['GET'])
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def advanced_search_form():
|
def advanced_search_form():
|
||||||
# Build custom columns names
|
# Build custom columns names
|
||||||
|
|
Loading…
Reference in New Issue
Block a user