From 870b2642a9a1384e656170f1a75533daf160c85e Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sat, 6 Mar 2021 21:54:39 -0500 Subject: [PATCH 1/9] advanced shelf search is almost working --- cps/templates/search_form.html | 165 ++++++++++++++++++--------------- cps/web.py | 21 ++++- 2 files changed, 111 insertions(+), 75 deletions(-) diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index 050028ac..7b478a77 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -16,20 +16,20 @@
-
- -
- - -
+
+ +
+ +
-
- -
- - -
+
+
+ +
+ +
+
@@ -42,17 +42,17 @@
- {% for tag in tags %} - + {% endfor %}
- {% for tag in tags %} - + {% endfor %}
@@ -60,64 +60,83 @@
- {% for serie in series %} - + {% endfor %}
- {% for serie in series %} - + {% endfor %}
+
+
+
+ +
+
+
+ +
+
+ {% if languages %}
- {% for language in languages %} - + {% endfor %}
- {% for language in languages %} - + {% endfor %}
{% endif%}
-
+
- + {% for extension in extensions %} + {% endfor %} -
-
+
+
- + {% for extension in extensions %} + {% endfor %} -
+
-
- - -
+
+ + +
@@ -129,47 +148,47 @@
{% if cc|length > 0 %} - {% for c in cc %} -
- - {% if c.datatype == 'bool' %} - - {% endif %} + {% for c in cc %} +
+ + {% if c.datatype == 'bool' %} + + {% endif %} - {% if c.datatype == 'int' %} - - {% endif %} + {% if c.datatype == 'int' %} + + {% endif %} - {% if c.datatype == 'float' %} - - {% endif %} + {% if c.datatype == 'float' %} + + {% endif %} - {% if c.datatype in ['text', 'series'] and not c.is_multiple %} - - {% endif %} + {% if c.datatype in ['text', 'series'] and not c.is_multiple %} + + {% endif %} - {% if c.datatype in ['text', 'series'] and c.is_multiple %} - - {% endif %} + {% if c.datatype in ['text', 'series'] and c.is_multiple %} + + {% endif %} - {% if c.datatype == 'enumeration' %} - - {% endif %} + {% if c.datatype == 'enumeration' %} + + {% endif %} - {% if c.datatype == 'rating' %} - - {% endif %} -
- {% endfor %} + {% if c.datatype == 'rating' %} + + {% endif %} +
+ {% endfor %} {% endif %} diff --git a/cps/web.py b/cps/web.py index 09744baf..ff61d42a 100644 --- a/cps/web.py +++ b/cps/web.py @@ -682,17 +682,21 @@ def render_prepare_search_form(cc): .group_by(text('books_series_link.series'))\ .order_by(db.Series.name)\ .filter(calibre_db.common_filters()).all() + shelves = ub.session.query(ub.Shelf)\ + .order_by(ub.Shelf.name).all() extensions = calibre_db.session.query(db.Data)\ .join(db.Books)\ .filter(calibre_db.common_filters()) \ .group_by(db.Data.format)\ .order_by(db.Data.format).all() + log.info(f"shelves: {shelves}") + log.info(f"series: {series}") if current_user.filter_language() == u"all": languages = calibre_db.speaking_language() else: languages = None 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): @@ -984,7 +988,7 @@ def search(): @login_required_if_no_ano def advanced_search(): 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'] for param in params: values[param] = list(request.form.getlist(param)) @@ -1004,6 +1008,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): exclude_tag_inputs = term.get('exclude_tag') include_series_inputs = term.get('include_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') exclude_languages_inputs = term.get('exclude_language') include_extension_inputs = term.get('include_extension') @@ -1033,6 +1039,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): cc_present = True 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 \ 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: @@ -1059,6 +1066,12 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): 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() 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).\ filter(db.Languages.id.in_(include_languages_inputs)).all() if language_names: @@ -1113,6 +1126,10 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): q = q.filter(db.Books.series.any(db.Series.id == serie)) for serie in exclude_series_inputs: q = q.filter(not_(db.Books.series.any(db.Series.id == serie))) + q = q.join(ub.BookShelf,db.Books.id==ub.BookShelf.book_id ,isouter=True)\ + .filter(ub.BookShelf.shelf.notin_(exclude_shelf_inputs)) + if len(include_shelf_inputs) >0: + q = q.filter(ub.BookShelf.shelf.in_(include_shelf_inputs)) for extension in include_extension_inputs: q = q.filter(db.Books.data.any(db.Data.format == extension)) for extension in exclude_extension_inputs: From 05139e53be84d91e18afe6eda3f963a3524d71e0 Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sat, 6 Mar 2021 22:15:18 -0500 Subject: [PATCH 2/9] advanced shelf search is working --- cps/web.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cps/web.py b/cps/web.py index ff61d42a..e7e5f065 100644 --- a/cps/web.py +++ b/cps/web.py @@ -37,7 +37,7 @@ from flask import session as flask_session from flask_babel import gettext as _ from flask_login import login_user, logout_user, login_required, current_user 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.sql.functions import coalesce @@ -1126,8 +1126,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): q = q.filter(db.Books.series.any(db.Series.id == serie)) for serie in exclude_series_inputs: q = q.filter(not_(db.Books.series.any(db.Series.id == serie))) - q = q.join(ub.BookShelf,db.Books.id==ub.BookShelf.book_id ,isouter=True)\ - .filter(ub.BookShelf.shelf.notin_(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)) for extension in include_extension_inputs: From 9711bd8fe1f0235d2cf1beaffd0386c8397e6fe1 Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sat, 6 Mar 2021 22:34:39 -0500 Subject: [PATCH 3/9] added actions boxes to drop downs --- cps/templates/search_form.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index 7b478a77..1d98b22b 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -60,7 +60,7 @@
- {% for serie in series %} {% endfor %} @@ -68,7 +68,7 @@
- {% for serie in series %} {% endfor %} @@ -78,7 +78,7 @@
- {% for shelf in shelves %} {% endfor %} @@ -86,7 +86,7 @@
- {% for shelf in shelves %} {% endfor %} @@ -98,7 +98,7 @@
- {% for language in languages %} {% endfor %} @@ -106,7 +106,7 @@
- {% for language in languages %} {% endfor %} @@ -117,7 +117,7 @@
- {% for extension in extensions %} {% endfor %} @@ -125,7 +125,7 @@
- {% for extension in extensions %} {% endfor %} From ff4502c63a89779e8a39a68b2f41a166245ce2be Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sun, 7 Mar 2021 15:23:05 -0500 Subject: [PATCH 4/9] Made shelf search user specific --- cps/web.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/web.py b/cps/web.py index e7e5f065..500d9c90 100644 --- a/cps/web.py +++ b/cps/web.py @@ -683,6 +683,7 @@ def render_prepare_search_form(cc): .order_by(db.Series.name)\ .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)\ .join(db.Books)\ From 9146e5f287b524dab51de7bf72cd4266eae8406a Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sun, 7 Mar 2021 19:53:54 -0500 Subject: [PATCH 5/9] fixed advanced search mass add to shelves in caliblur --- cps/static/js/caliBlur.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cps/static/js/caliBlur.js b/cps/static/js/caliBlur.js index 7769a4ea..dab2a1c6 100644 --- a/cps/static/js/caliBlur.js +++ b/cps/static/js/caliBlur.js @@ -403,6 +403,14 @@ $("div.comments").readmore({ // End of Global Work // /////////////////////////////// +// Advanced Search Results +if($("body.advsearch").length > 0) { + $('div[aria-label="Add to shelves"]').click(function () { + $("#add-to-shelves").toggle(); + }); + $('#add-to-shelf').height("40px"); +} + // Author Page Background Blur if ($("body.author").length > 0) { cover = $(".author-bio img").attr("src"); From 83474da7b57f9c58e082c4c200f0d5415a050bd4 Mon Sep 17 00:00:00 2001 From: cbartondock Date: Sun, 7 Mar 2021 22:54:34 -0500 Subject: [PATCH 6/9] fixed being able to click through dropdown in advanced search results --- cps/static/js/caliBlur.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cps/static/js/caliBlur.js b/cps/static/js/caliBlur.js index dab2a1c6..d4c43bcc 100644 --- a/cps/static/js/caliBlur.js +++ b/cps/static/js/caliBlur.js @@ -405,10 +405,35 @@ $("div.comments").readmore({ // Advanced Search Results if($("body.advsearch").length > 0) { + $("#loader + .container-fluid") + .prepend("
"); + $("#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 From f5ded86c02da06678d11e3719c4238e217730f06 Mon Sep 17 00:00:00 2001 From: cbartondock Date: Tue, 16 Mar 2021 19:18:57 -0400 Subject: [PATCH 7/9] removed extraneous logs --- cps/web.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cps/web.py b/cps/web.py index 62491911..a518a8e5 100644 --- a/cps/web.py +++ b/cps/web.py @@ -695,8 +695,6 @@ def render_prepare_search_form(cc): .filter(calibre_db.common_filters()) \ .group_by(db.Data.format)\ .order_by(db.Data.format).all() - log.info(f"shelves: {shelves}") - log.info(f"series: {series}") if current_user.filter_language() == u"all": languages = calibre_db.speaking_language() else: From 081553dc9faa0ee50c85e46cc0be67929adca5f8 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 20 Mar 2021 16:27:47 +0100 Subject: [PATCH 8/9] Disable blank issue templates --- .github/ISSUE_TEMPLATE/config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..3ba13e0c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false From b1b7ee65b4e041e56faeb535ff07c7f00e8ee30a Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 20 Mar 2021 18:10:27 +0100 Subject: [PATCH 9/9] Refactored advanced search --- cps/config_sql.py | 2 +- cps/web.py | 98 ++++++++++++++++++++--------------------------- 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index 60e17eb3..b80a6866 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -66,7 +66,7 @@ class _Settings(_Base): config_random_books = Column(Integer, default=4) config_authors_max = Column(Integer, default=0) config_read_column = Column(Integer, default=0) - config_title_regex = Column(String, default=u'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+') + config_title_regex = Column(String, default=r'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+') config_mature_content_tags = Column(String, default='') config_theme = Column(Integer, default=0) diff --git a/cps/web.py b/cps/web.py index a518a8e5..8e4ce297 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1085,9 +1085,9 @@ def adv_search_serie(q, include_series_inputs, exclude_series_inputs): 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.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 @@ -1097,18 +1097,10 @@ def extend_search_term(searchterm, publisher, pub_start, pub_end, - include_tag_inputs, - exclude_tag_inputs, - include_series_inputs, - exclude_series_inputs, - include_shelf_inputs, - exclude_shelf_inputs, - include_languages_inputs, + tags, rating_high, rating_low, read_status, - include_extension_inputs, - exclude_extension_inputs ): searchterm.extend((author_name.replace('|', ','), book_title, publisher)) if pub_start: @@ -1125,20 +1117,27 @@ def extend_search_term(searchterm, format='medium', locale=get_locale())]) except ValueError: pub_start = u"" - tag_names = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(include_tag_inputs)).all() - searchterm.extend(tag.name for tag in tag_names) - tag_names = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(exclude_tag_inputs)).all() - 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) - 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) - 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) + elements = {'tag': db.Tags, 'serie':db.Series, 'shelf':ub.Shelf} + for key, db_element in elements.items(): + tag_names = calibre_db.session.query(db_element).filter(db_element.id.in_(tags['include_' + key])).all() + searchterm.extend(tag.name for tag in tag_names) + tag_names = calibre_db.session.query(db_element).filter(db.Tags.id.in_(tags['exclude_' + key])).all() + searchterm.extend(tag.name for tag in tag_names) + #serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(tags['include_serie'])).all() + #searchterm.extend(serie.name for serie in serie_names) + #serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(tags['include_serie'])).all() + #searchterm.extend(serie.name for serie in serie_names) + #shelf_names = ub.session.query(ub.Shelf).filter(ub.Shelf.id.in_(tags['include_shelf'])).all() + #searchterm.extend(shelf.name for shelf in shelf_names) + #shelf_names = ub.session.query(ub.Shelf).filter(ub.Shelf.id.in_(tags['include_shelf'])).all() + #searchterm.extend(shelf.name for shelf in shelf_names) language_names = calibre_db.session.query(db.Languages). \ - filter(db.Languages.id.in_(include_languages_inputs)).all() + filter(db.Languages.id.in_(tags['include_language'])).all() + if language_names: + language_names = calibre_db.speaking_language(language_names) + searchterm.extend(language.name for language in language_names) + language_names = calibre_db.session.query(db.Languages). \ + filter(db.Languages.id.in_(tags['exclude_language'])).all() if language_names: language_names = calibre_db.speaking_language(language_names) searchterm.extend(language.name for language in language_names) @@ -1148,8 +1147,8 @@ def extend_search_term(searchterm, searchterm.extend([_(u"Rating >= %(rating)s", rating=rating_low)]) if read_status: searchterm.extend([_(u"Read Status = %(status)s", status=read_status)]) - searchterm.extend(ext for ext in include_extension_inputs) - searchterm.extend(ext for ext in exclude_extension_inputs) + searchterm.extend(ext for ext in tags['include_extension']) + searchterm.extend(ext for ext in tags['exclude_extension']) # handle custom columns searchterm = " + ".join(filter(None, searchterm)) return searchterm, pub_start, pub_end @@ -1163,16 +1162,12 @@ 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 = 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_shelf_inputs = term.get('include_shelf') - exclude_shelf_inputs = term.get('exclude_shelf') - 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') + # parse multiselects to a complete dict + tags = dict() + elements = ['tag', 'serie', 'shelf', 'language', 'extension'] + for element in elements: + tags['include_' + element] = term.get('include_' + element) + tags['exclude_' + element] = term.get('exclude_' + element) author_name = term.get("author_name") book_title = term.get("book_title") @@ -1197,29 +1192,18 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): 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_shelf_inputs or exclude_shelf_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 or read_status: + if any(tags.values()) 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 read_status: searchterm, pub_start, pub_end = extend_search_term(searchterm, author_name, book_title, publisher, pub_start, pub_end, - include_tag_inputs, - exclude_tag_inputs, - include_series_inputs, - exclude_series_inputs, - include_shelf_inputs, - exclude_shelf_inputs, - include_languages_inputs, + tags, rating_high, rating_low, - read_status, - include_extension_inputs, - exclude_extension_inputs) + read_status) q = q.filter() if author_name: q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_name + "%"))) @@ -1232,11 +1216,11 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): q = adv_search_read_status(q, read_status) if 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_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_language(q, include_languages_inputs, exclude_languages_inputs) + q = adv_search_tag(q, tags['include_tag'], tags['exclude_tag']) + q = adv_search_serie(q, tags['include_serie'], tags['exclude_serie']) + q = adv_search_shelf(q, tags['include_shelf'], tags['exclude_shelf']) + q = adv_search_extension(q, tags['include_extension'], tags['exclude_extension']) + q = adv_search_language(q, tags['include_language'], tags['exclude_language']) q = adv_search_ratings(q, rating_high, rating_low) if description: