Fix for #1660 (advanced search for custom columns working, headline for advanced search working)

This commit is contained in:
Ozzieisaacs 2020-10-16 20:24:15 +02:00
parent 2814617e4b
commit bc0416cbb4

View File

@ -1242,10 +1242,15 @@ def search():
page="search")
@web.route("/advanced_search", methods=['POST'])
@web.route("/advsearch", methods=['POST'])
@login_required_if_no_ano
def advanced_search():
flask_session['query'] = json.dumps(request.form)
values = dict(request.form)
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=""))
@ -1257,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)
q = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(True))
include_tag_inputs = request.form.getlist('include_tag')
exclude_tag_inputs = request.form.getlist('exclude_tag')
include_series_inputs = request.form.getlist('include_serie')
exclude_series_inputs = request.form.getlist('exclude_serie')
include_languages_inputs = request.form.getlist('include_language')
exclude_languages_inputs = request.form.getlist('exclude_language')
include_extension_inputs = request.form.getlist('include_extension')
exclude_extension_inputs = request.form.getlist('exclude_extension')
include_tag_inputs = term.get('include_tag')
exclude_tag_inputs = term.get('exclude_tag')
include_series_inputs = term.get('include_serie')
exclude_series_inputs = term.get('exclude_serie')
include_languages_inputs = term.get('include_language')
exclude_languages_inputs = term.get('exclude_language')
include_extension_inputs = term.get('include_extension')
exclude_extension_inputs = term.get('exclude_extension')
author_name = term.get("author_name")
book_title = term.get("book_title")
@ -1284,15 +1289,14 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
searchterm = []
cc_present = False
for c in cc:
if request.form.get('custom_column_' + str(c.id)):
searchterm.extend([(u"%s: %s" % (c.name, request.form.get('custom_column_' + str(c.id))))])
if term.get('custom_column_' + str(c.id)):
searchterm.extend([(u"%s: %s" % (c.name, term.get('custom_column_' + str(c.id))))])
cc_present = True
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 \
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:
searchterm = []
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 \
include_extension_inputs or exclude_extension_inputs:
searchterm.extend((author_name.replace('|', ','), book_title, publisher))
if pub_start:
try:
@ -1312,7 +1316,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
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()
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:
language_names = calibre_db.speaking_language(language_names)
searchterm.extend(language.name for language in language_names)
@ -1323,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 exclude_extension_inputs)
# handle custom columns
for c in cc:
if request.form.get('custom_column_' + str(c.id)):
searchterm.extend([(u"%s: %s" % (c.name, request.form.get('custom_column_' + str(c.id))))])
#for c in cc:
# if term.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))
q = q.filter()
if author_name:
@ -1368,7 +1373,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
# search custom culumns
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 c.datatype == 'bool':
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
@ -1403,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
def advanced_search_form():
# Build custom columns names