Merge remote-tracking branch 'adv_search/master' into master

This commit is contained in:
Ozzie Isaacs 2021-03-20 17:48:21 +01:00
commit 6889456662
3 changed files with 149 additions and 76 deletions

View File

@ -403,6 +403,39 @@ $("div.comments").readmore({
// End of Global Work // // End of Global Work //
/////////////////////////////// ///////////////////////////////
// Advanced Search Results
if($("body.advsearch").length > 0) {
$("#loader + .container-fluid")
.prepend("<div class='blur-wrapper'></div>");
$("#add-to-shelves").insertBefore(".blur-wrapper");
$('div[aria-label="Add to shelves"]').click(function () {
$("#add-to-shelves").toggle();
});
$('#add-to-shelf').height("40px");
function dropdownToggle() {
topPos = $("#add-to-shelf").offset().top-20;
if ($('div[aria-label="Add to shelves"]').length > 0) {
position = $('div[aria-label="Add to shelves"]').offset().left
if (position + $("#add-to-shelves").width() > $(window).width()) {
positionOff = position + $("#add-to-shelves").width() - $(window).width();
adsPosition = position - positionOff - 5
$("#add-to-shelves").attr("style", "left: " + adsPosition + "px !important; right: auto; top: " + topPos + "px");
} else {
$("#add-to-shelves").attr("style", "left: " + position + "px !important; right: auto; top: " + topPos + "px");
}
}
}
dropdownToggle();
$(window).on("resize", function () {
dropdownToggle();
});
}
// Author Page Background Blur // Author Page Background Blur
if ($("body.author").length > 0) { if ($("body.author").length > 0) {
cover = $(".author-bio img").attr("src"); cover = $(".author-bio img").attr("src");

View File

@ -42,7 +42,7 @@
<div class="row"> <div class="row">
<div class="form-group col-sm-6" id="tag"> <div class="form-group col-sm-6" id="tag">
<div><label for="include_tag">{{_('Tags')}}</label></div> <div><label for="include_tag">{{_('Tags')}}</label></div>
<select class="selectpicker" name="include_tag" id="include_tag" data-live-search="true" data-style="btn-primary" multiple> <select class="selectpicker" name="include_tag" id="include_tag" data-live-search="true" data-style="btn-primary" data-dropup-auto="false" multiple>
{% for tag in tags %} {% for tag in tags %}
<option class="tags_click" value="{{tag.id}}">{{tag.name}}</option> <option class="tags_click" value="{{tag.id}}">{{tag.name}}</option>
{% endfor %} {% endfor %}
@ -50,7 +50,7 @@
</div> </div>
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="exclude_tag">{{_('Exclude Tags')}}</label></div> <div><label for="exclude_tag">{{_('Exclude Tags')}}</label></div>
<select class="selectpicker" name="exclude_tag" id="exclude_tag" data-live-search="true" data-style="btn-danger" multiple> <select class="selectpicker" name="exclude_tag" id="exclude_tag" data-live-search="true" data-style="btn-danger" data-dropup-auto="false" multiple>
{% for tag in tags %} {% for tag in tags %}
<option class="tags_click" value="{{tag.id}}">{{tag.name}}</option> <option class="tags_click" value="{{tag.id}}">{{tag.name}}</option>
{% endfor %} {% endfor %}
@ -60,7 +60,7 @@
<div class="row"> <div class="row">
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="include_serie">{{_('Series')}}</label></div> <div><label for="include_serie">{{_('Series')}}</label></div>
<select class="selectpicker" name="include_serie" id="include_serie" data-live-search="true" data-style="btn-primary" multiple> <select class="selectpicker" name="include_serie" id="include_serie" data-live-search="true" data-style="btn-primary" data-dropup-auto="false" data-actions-box="true" multiple>
{% for serie in series %} {% for serie in series %}
<option value="{{serie.id}}">{{serie.name}}</option> <option value="{{serie.id}}">{{serie.name}}</option>
{% endfor %} {% endfor %}
@ -68,18 +68,37 @@
</div> </div>
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="exclude_serie">{{_('Exclude Series')}}</label></div> <div><label for="exclude_serie">{{_('Exclude Series')}}</label></div>
<select class="selectpicker" name="exclude_serie" id="exclude_serie" data-live-search="true" data-style="btn-danger" multiple> <select class="selectpicker" name="exclude_serie" id="exclude_serie" data-live-search="true" data-style="btn-danger" data-dropup-auto="false" data-actions-box="true" multiple>
{% for serie in series %} {% for serie in series %}
<option value="{{serie.id}}">{{serie.name}}</option> <option value="{{serie.id}}">{{serie.name}}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div> </div>
<div class="row">
<div class="form-group col-sm-6">
<div><label for="include_shelf">{{_('Shelves')}}</label></div>
<select class="selectpicker" name="include_shelf" id="include_shelf" data-live-search="true" data-style="btn-primary" data-dropup-auto="false" data-actions-box="true" multiple>
{% for shelf in shelves %}
<option value="{{shelf.id}}">{{shelf.name}}</option>
{% endfor %}
</select>
</div>
<div class="form-group col-sm-6">
<div><label for="exclude_shelf">{{_('Exclude Shelves')}}</label></div>
<select class="selectpicker" name="exclude_shelf" id="exclude_shelf" data-live-search="true" data-style="btn-danger" data-dropup-auto="false" data-actions-box="true" multiple>
{% for shelf in shelves %}
<option value="{{shelf.id}}">{{shelf.name}}</option>
{% endfor %}
</select>
</div>
</div>
{% if languages %} {% if languages %}
<div class="row"> <div class="row">
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="include_language">{{_('Languages')}}</label></div> <div><label for="include_language">{{_('Languages')}}</label></div>
<select class="selectpicker" name="include_language" id="include_language" data-live-search="true" data-style="btn-primary" multiple> <select class="selectpicker" name="include_language" id="include_language" data-live-search="true" data-style="btn-primary" data-dropup-auto="false" data-actions-box="true" multiple>
{% for language in languages %} {% for language in languages %}
<option value="{{language.id}}">{{language.name}}</option> <option value="{{language.id}}">{{language.name}}</option>
{% endfor %} {% endfor %}
@ -87,7 +106,7 @@
</div> </div>
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="exclude_language">{{_('Exclude Languages')}}</label></div> <div><label for="exclude_language">{{_('Exclude Languages')}}</label></div>
<select class="selectpicker" name="exclude_language" id="exclude_language" data-live-search="true" data-style="btn-danger" multiple> <select class="selectpicker" name="exclude_language" id="exclude_language" data-live-search="true" data-style="btn-danger" data-dropup-auto="false" data-actions-box="true" multiple>
{% for language in languages %} {% for language in languages %}
<option value="{{language.id}}">{{language.name}}</option> <option value="{{language.id}}">{{language.name}}</option>
{% endfor %} {% endfor %}
@ -98,7 +117,7 @@
<div class="row"> <div class="row">
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="include_extension">{{_('Extensions')}}</label></div> <div><label for="include_extension">{{_('Extensions')}}</label></div>
<select class="selectpicker" name="include_extension" id="include_extension" data-live-search="true" data-style="btn-primary" multiple> <select class="selectpicker" name="include_extension" id="include_extension" data-live-search="true" data-style="btn-primary" data-dropup-auto="false" data-actions-box="true" multiple>
{% for extension in extensions %} {% for extension in extensions %}
<option value="{{extension.format}}">{{extension.format}}</option> <option value="{{extension.format}}">{{extension.format}}</option>
{% endfor %} {% endfor %}
@ -106,7 +125,7 @@
</div> </div>
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<div><label for="exclude_extension">{{_('Exclude Extensions')}}</label></div> <div><label for="exclude_extension">{{_('Exclude Extensions')}}</label></div>
<select class="selectpicker" name="exclude_extension" id="exclude_extension" data-live-search="true" data-style="btn-danger" multiple> <select class="selectpicker" name="exclude_extension" id="exclude_extension" data-live-search="true" data-style="btn-danger" data-dropup-auto="false" data-actions-box="true" multiple>
{% for extension in extensions %} {% for extension in extensions %}
<option value="{{extension.format}}">{{extension.format}}</option> <option value="{{extension.format}}">{{extension.format}}</option>
{% endfor %} {% endfor %}

View File

@ -37,7 +37,7 @@ from flask import session as flask_session
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_login import login_user, logout_user, login_required, current_user from flask_login import login_user, logout_user, login_required, current_user
from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError
from sqlalchemy.sql.expression import text, func, false, not_, and_ from sqlalchemy.sql.expression import text, func, false, not_, and_, or_
from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.sql.functions import coalesce from sqlalchemy.sql.functions import coalesce
@ -687,6 +687,9 @@ def render_prepare_search_form(cc):
.group_by(text('books_series_link.series'))\ .group_by(text('books_series_link.series'))\
.order_by(db.Series.name)\ .order_by(db.Series.name)\
.filter(calibre_db.common_filters()).all() .filter(calibre_db.common_filters()).all()
shelves = ub.session.query(ub.Shelf)\
.filter(or_(ub.Shelf.is_public == 1, ub.Shelf.user_id == int(current_user.id)))\
.order_by(ub.Shelf.name).all()
extensions = calibre_db.session.query(db.Data)\ extensions = calibre_db.session.query(db.Data)\
.join(db.Books)\ .join(db.Books)\
.filter(calibre_db.common_filters()) \ .filter(calibre_db.common_filters()) \
@ -697,7 +700,7 @@ def render_prepare_search_form(cc):
else: else:
languages = None languages = None
return render_title_template('search_form.html', tags=tags, languages=languages, extensions=extensions, return render_title_template('search_form.html', tags=tags, languages=languages, extensions=extensions,
series=series, title=_(u"Advanced Search"), cc=cc, page="advsearch") series=series,shelves=shelves, title=_(u"Advanced Search"), cc=cc, page="advsearch")
def render_search_results(term, offset=None, order=None, limit=None): def render_search_results(term, offset=None, order=None, limit=None):
@ -989,7 +992,7 @@ def search():
@login_required_if_no_ano @login_required_if_no_ano
def advanced_search(): def advanced_search():
values = dict(request.form) values = dict(request.form)
params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_language', params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_shelf','exclude_shelf','include_language',
'exclude_language', 'include_extension', 'exclude_extension'] 'exclude_language', 'include_extension', 'exclude_extension']
for param in params: for param in params:
values[param] = list(request.form.getlist(param)) values[param] = list(request.form.getlist(param))
@ -1081,6 +1084,12 @@ def adv_search_serie(q, include_series_inputs, exclude_series_inputs):
q = q.filter(not_(db.Books.series.any(db.Series.id == serie))) q = q.filter(not_(db.Books.series.any(db.Series.id == serie)))
return q return q
def adv_search_shelf(q, include_shelf_inputs, exclude_shelf_inputs):
q = q.outerjoin(ub.BookShelf,db.Books.id==ub.BookShelf.book_id)\
.filter(or_(ub.BookShelf.shelf==None,ub.BookShelf.shelf.notin_(exclude_shelf_inputs)))
if len(include_shelf_inputs) >0:
q = q.filter(ub.BookShelf.shelf.in_(include_shelf_inputs))
return q
def extend_search_term(searchterm, def extend_search_term(searchterm,
author_name, author_name,
@ -1092,6 +1101,8 @@ def extend_search_term(searchterm,
exclude_tag_inputs, exclude_tag_inputs,
include_series_inputs, include_series_inputs,
exclude_series_inputs, exclude_series_inputs,
include_shelf_inputs,
exclude_shelf_inputs,
include_languages_inputs, include_languages_inputs,
rating_high, rating_high,
rating_low, rating_low,
@ -1122,6 +1133,10 @@ def extend_search_term(searchterm,
searchterm.extend(serie.name for serie in serie_names) searchterm.extend(serie.name for serie in serie_names)
serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(exclude_series_inputs)).all() serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(exclude_series_inputs)).all()
searchterm.extend(serie.name for serie in serie_names) searchterm.extend(serie.name for serie in serie_names)
shelf_names = ub.session.query(ub.Shelf).filter(ub.Shelf.id.in_(include_shelf_inputs)).all()
searchterm.extend(shelf.name for shelf in shelf_names)
shelf_names = ub.session.query(ub.Shelf).filter(ub.Shelf.id.in_(exclude_shelf_inputs)).all()
searchterm.extend(shelf.name for shelf in shelf_names)
language_names = calibre_db.session.query(db.Languages). \ language_names = calibre_db.session.query(db.Languages). \
filter(db.Languages.id.in_(include_languages_inputs)).all() filter(db.Languages.id.in_(include_languages_inputs)).all()
if language_names: if language_names:
@ -1152,6 +1167,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
exclude_tag_inputs = term.get('exclude_tag') exclude_tag_inputs = term.get('exclude_tag')
include_series_inputs = term.get('include_serie') include_series_inputs = term.get('include_serie')
exclude_series_inputs = term.get('exclude_serie') exclude_series_inputs = term.get('exclude_serie')
include_shelf_inputs = term.get('include_shelf')
exclude_shelf_inputs = term.get('exclude_shelf')
include_languages_inputs = term.get('include_language') include_languages_inputs = term.get('include_language')
exclude_languages_inputs = term.get('exclude_language') exclude_languages_inputs = term.get('exclude_language')
include_extension_inputs = term.get('include_extension') include_extension_inputs = term.get('include_extension')
@ -1181,6 +1198,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
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_shelf_inputs or exclude_shelf_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 or read_status: include_extension_inputs or exclude_extension_inputs or read_status:
@ -1194,6 +1212,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
exclude_tag_inputs, exclude_tag_inputs,
include_series_inputs, include_series_inputs,
exclude_series_inputs, exclude_series_inputs,
include_shelf_inputs,
exclude_shelf_inputs,
include_languages_inputs, include_languages_inputs,
rating_high, rating_high,
rating_low, rating_low,
@ -1214,6 +1234,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
q = q.filter(db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + publisher + "%"))) q = q.filter(db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + publisher + "%")))
q = adv_search_tag(q, include_tag_inputs, exclude_tag_inputs) q = adv_search_tag(q, include_tag_inputs, exclude_tag_inputs)
q = adv_search_serie(q, include_series_inputs, exclude_series_inputs) q = adv_search_serie(q, include_series_inputs, exclude_series_inputs)
q = adv_search_shelf(q, include_shelf_inputs, exclude_shelf_inputs)
q = adv_search_extension(q, include_extension_inputs, exclude_extension_inputs) q = adv_search_extension(q, include_extension_inputs, exclude_extension_inputs)
q = adv_search_language(q, include_languages_inputs, exclude_languages_inputs) q = adv_search_language(q, include_languages_inputs, exclude_languages_inputs)
q = adv_search_ratings(q, rating_high, rating_low) q = adv_search_ratings(q, rating_high, rating_low)