diff --git a/cps/__init__.py b/cps/__init__.py old mode 100755 new mode 100644 diff --git a/cps/admin.py b/cps/admin.py old mode 100755 new mode 100644 diff --git a/cps/redirect.py b/cps/redirect.py old mode 100755 new mode 100644 diff --git a/cps/search.py b/cps/search.py index 4ae8a5d7..6054ec9e 100644 --- a/cps/search.py +++ b/cps/search.py @@ -24,6 +24,7 @@ from flask_babel import format_date from flask_babel import gettext as _ from sqlalchemy.sql.expression import func, not_, and_, or_, text, true from sqlalchemy.sql.functions import coalesce +from sqlalchemy import exists from . import logger, db, calibre_db, config, ub from .usermanagement import login_required_if_no_ano @@ -81,16 +82,27 @@ def adv_search_custom_columns(cc, term, q): if custom_end: q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( func.datetime(db.cc_classes[c.id].value) <= func.datetime(custom_end))) + elif c.datatype in ["int", "float"]: + custom_low = term.get('custom_column_' + str(c.id) + '_low') + custom_high = term.get('custom_column_' + str(c.id) + '_high') + if custom_low: + q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( + db.cc_classes[c.id].value >= custom_low)) + if custom_high: + q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( + db.cc_classes[c.id].value <= custom_high)) else: 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( - db.cc_classes[c.id].value == (custom_query == "True"))) - elif c.datatype == 'int' or c.datatype == 'float': - q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( - db.cc_classes[c.id].value == custom_query)) - elif c.datatype == 'rating': + if c.datatype == 'bool': + if custom_query != "Any": + if custom_query == "": + q = q.filter(~getattr(db.Books, 'custom_column_' + str(c.id)). + any(db.cc_classes[c.id].value >= 0)) + else: + q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( + db.cc_classes[c.id].value == bool(custom_query == "True"))) + elif custom_query != '' and custom_query is not None: + if c.datatype == 'rating': q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( db.cc_classes[c.id].value == int(float(custom_query) * 2))) else: @@ -129,10 +141,10 @@ def adv_search_read_status(read_status): db_filter = coalesce(ub.ReadBook.read_status, 0) != ub.ReadBook.STATUS_FINISHED else: try: - if read_status == "True": - db_filter = db.cc_classes[config.config_read_column].value == True + if read_status == "": + db_filter = coalesce(db.cc_classes[config.config_read_column].value, 2) == 2 else: - db_filter = coalesce(db.cc_classes[config.config_read_column].value, False) != True + db_filter = db.cc_classes[config.config_read_column].value == bool(read_status == "True") except (KeyError, AttributeError, IndexError): log.error("Custom Column No.{} does not exist in calibre database".format(config.config_read_column)) flash(_("Custom Column No.%(column)d does not exist in calibre database", @@ -275,10 +287,23 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): cc_present = True if column_end: search_term.extend(["{} <= {}".format(c.name, - format_date(datetime.strptime(column_end, "%Y-%m-%d").date(), + format_date(datetime.strptime(column_end, "%Y-%m-%d").date(), format='medium') )]) cc_present = True + if c.datatype in ["int", "float"]: + column_low = term.get('custom_column_' + str(c.id) + '_low') + column_high = term.get('custom_column_' + str(c.id) + '_high') + if column_low: + search_term.extend(["{} >= {}".format(c.name, column_low)]) + cc_present = True + if column_high: + search_term.extend(["{} <= {}".format(c.name,column_high)]) + cc_present = True + elif c.datatype == "bool": + if term.get('custom_column_' + str(c.id)) != "Any": + search_term.extend([("{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))]) + cc_present = True elif term.get('custom_column_' + str(c.id)): search_term.extend([("{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))]) cc_present = True diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index cf2fac04..cdce85a5 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -158,21 +158,41 @@ {% if cc|length > 0 %} {% for c in cc %}
+ {% if c.datatype == 'bool' %} {% endif %} {% if c.datatype == 'int' %} - +
+
+ + +
+
+ + +
+
{% endif %} - {% if c.datatype == 'float' %} - +
+
+ + +
+
+ + +
+
+ {% endif %} {% if c.datatype == 'datetime' %} diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index b21f11ff..288c7443 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2024-07-29 06:08:20

+

Start Time: 2024-07-18 20:53:44

-

Stop Time: 2024-07-29 13:40:23

+

Stop Time: 2024-07-19 03:48:09

-

Duration: 6h 9 min

+

Duration: 5h 43 min

@@ -234,11 +234,11 @@ - + TestBackupMetadata 21 - 20 - 1 + 21 + 0 0 0 @@ -248,33 +248,11 @@ - +
TestBackupMetadata - test_backup_all
- -
- FAIL -
- - - - + PASS @@ -484,12 +462,12 @@ AssertionError: 'Finished' != 'Failed' - + TestCli 13 - 11 + 13 + 0 0 - 2 0 Detail @@ -588,31 +566,11 @@ AssertionError: 'Finished' != 'Failed' - +
TestCli - test_no_database
- -
- ERROR -
- - - - + PASS @@ -626,53 +584,22 @@ OSError: [Errno 39] Directory not empty: '/home/ozzie/Dusty/script/alternate - +
TestCli - test_writeonly_static_files
- -
- ERROR -
- - - - + PASS - + TestCliGdrivedb 4 - 3 + 4 + 0 0 - 1 0 Detail @@ -708,31 +635,11 @@ bail@chrome://remote/content/marionette/sync.sys.mjs:211:19 - +
TestCliGdrivedb - test_no_database
- -
- ERROR -
- - - - + PASS @@ -1107,11 +1014,11 @@ OSError: [Errno 39] Directory not empty: '/home/ozzie/Dusty/script/alternate - + TestEditAdditionalBooks 20 - 17 - 1 + 18 + 0 0 2 @@ -1282,31 +1189,11 @@ OSError: [Errno 39] Directory not empty: '/home/ozzie/Dusty/script/alternate - +
TestEditAdditionalBooks - test_writeonly_path
- -
- FAIL -
- - - - + PASS @@ -1730,11 +1617,11 @@ AssertionError: False is not true - + TestEditAuthors 9 - 5 - 4 + 9 + 0 0 0 @@ -1753,118 +1640,38 @@ AssertionError: False is not true - +
TestEditAuthors - test_change_capital_one_author_one_book
- -
- FAIL -
- - - - + PASS - +
TestEditAuthors - test_change_capital_one_author_two_books
- -
- FAIL -
- - - - + PASS - +
TestEditAuthors - test_change_capital_one_author_two_books_coauthor
- -
- FAIL -
- - - - + PASS - +
TestEditAuthors - test_change_capital_rename_co_author
- -
- FAIL -
- - - - + PASS @@ -1985,116 +1792,20 @@ AssertionError: True is not false - TestEditAuthorsSmb - 9 - 9 + TestEditBooksList + 19 + 19 0 0 0 - Detail + Detail - -
TestEditAuthorsSmb - test_change_capital_co_author
- - PASS - - - - - - -
TestEditAuthorsSmb - test_change_capital_one_author_one_book
- - PASS - - - - - - -
TestEditAuthorsSmb - test_change_capital_one_author_two_books
- - PASS - - - - - - -
TestEditAuthorsSmb - test_change_capital_one_author_two_books_coauthor
- - PASS - - - - - - -
TestEditAuthorsSmb - test_change_capital_rename_co_author
- - PASS - - - - - - -
TestEditAuthorsSmb - test_change_capital_rename_two_co_authors
- - PASS - - - - - - -
TestEditAuthorsSmb - test_rename_author_emphasis_mark_onupload
- - PASS - - - - - - -
TestEditAuthorsSmb - test_rename_capital_on_upload
- - PASS - - - - - - -
TestEditAuthorsSmb - test_rename_tag_emphasis_mark_onupload
- - PASS - - - - - - - TestEditBooksList - 19 - 18 - 1 - 0 - 0 - - Detail - - - - - -
TestEditBooksList - test_booklist_xss
@@ -2103,7 +1814,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_author
@@ -2112,7 +1823,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_categories
@@ -2121,7 +1832,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_comment
@@ -2130,7 +1841,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_category
@@ -2139,7 +1850,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_comment
@@ -2148,7 +1859,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_enum
@@ -2157,7 +1868,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_float
@@ -2166,7 +1877,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_int
@@ -2175,7 +1886,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_ratings
@@ -2184,7 +1895,7 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_cust_text
@@ -2193,36 +1904,16 @@ AssertionError: True is not false - +
TestEditBooksList - test_bookslist_edit_languages
- -
- FAIL -
- - - - + PASS - +
TestEditBooksList - test_bookslist_edit_publisher
@@ -2231,7 +1922,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_bookslist_edit_series
@@ -2240,7 +1931,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_bookslist_edit_seriesindex
@@ -2249,7 +1940,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_bookslist_edit_title
@@ -2258,7 +1949,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_list_visibility
@@ -2267,7 +1958,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_restricted_rights
@@ -2276,7 +1967,7 @@ AssertionError: False is not true - +
TestEditBooksList - test_search_books_list
@@ -2294,25 +1985,25 @@ AssertionError: False is not true 1 0 - Detail + Detail - +
TestLoadMetadata - test_load_metadata
- ERROR + ERROR
-