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 %}
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
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 69, in test_backup_all - self.assertEqual(tasks[-1]['result'], "Failed") -AssertionError: 'Finished' != 'Failed' -- Finished -+ Failed-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli.py", line 602, in test_no_database - os.rmdir(alt_location) -OSError: [Errno 39] Directory not empty: '/home/ozzie/Dusty/script/alternate'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli.py", line 732, in test_writeonly_static_files - self.driver.get("http://127.0.0.1:" + PORTS[0]) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 449, in get - self.execute(Command.GET, {"url": url}) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute - self.error_handler.check_response(response) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response - raise exception_class(message, screen, stacktrace) -selenium.common.exceptions.TimeoutException: Message: Navigation timed out after 300000 ms -Stacktrace: -RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 -WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5 -TimeoutError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:740:5 -bail@chrome://remote/content/marionette/sync.sys.mjs:211:19-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_cli_gdrive.py", line 283, in test_no_database - os.rmdir(alt_location) -OSError: [Errno 39] Directory not empty: '/home/ozzie/Dusty/script/alternate'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_additional_books.py", line 417, in test_writeonly_path - self.assertTrue(self.check_element_on_page((By.ID, "flash_danger"))) -AssertionError: False is not true-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author.py", line 62, in test_change_capital_one_author_one_book - self.assertFalse(os.path.isdir(os.path.join(TEST_DB, 'Leo Baskerville'))) -AssertionError: True is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author.py", line 111, in test_change_capital_one_author_two_books - self.assertFalse(os.path.isdir(os.path.join(TEST_DB, 'Peter Parker'))) -AssertionError: True is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author.py", line 164, in test_change_capital_one_author_two_books_coauthor - self.assertFalse(os.path.isdir(os.path.join(TEST_DB, 'Norbert Halagal'))) -AssertionError: True is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_author.py", line 294, in test_change_capital_rename_co_author - self.assertFalse(os.path.isdir(os.path.join(TEST_DB, 'Hector Gonçalves'))) -AssertionError: True is not false-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 230, in test_bookslist_edit_languages - self.assertTrue("+" in self.check_element_on_page((By.XPATH, -AssertionError: False is not true-