From 4745fc0db171beac8ecb0f1aafd9ae615090fd22 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 15 May 2021 07:51:32 +0200 Subject: [PATCH 1/2] Bugfix search for publish dates and custom column dates Bugfix save umplauts in comments unescaped (as calibre does) Improved testability --- cps/editbooks.py | 4 +++- cps/templates/book_edit.html | 2 +- cps/templates/search_form.html | 20 ++++++++++---------- cps/web.py | 12 ++++++------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index a155e029..573b0d6f 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -501,6 +501,8 @@ def edit_cc_data_value(book_id, book, c, to_save, cc_db_value, cc_string): to_save[cc_string] = None elif c.datatype == 'bool': to_save[cc_string] = 1 if to_save[cc_string] == 'True' else 0 + elif c.datatype == 'comments': + to_save[cc_string] = Markup(to_save[cc_string]).unescape() elif c.datatype == 'datetime': try: to_save[cc_string] = datetime.strptime(to_save[cc_string], "%Y-%m-%d") @@ -772,7 +774,7 @@ def edit_book(book_id): # Add default series_index to book modif_date |= edit_book_series_index(to_save["series_index"], book) # Handle book comments/description - modif_date |= edit_book_comments(to_save["description"], book) + modif_date |= edit_book_comments(Markup(to_save['description']).unescape(), book) # Handle identifiers input_identifiers = identifier_list(to_save, book) modification, warning = modify_identifiers(input_identifiers, book.identifiers, calibre_db.session) diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 1493e289..a14e2b72 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -161,7 +161,7 @@ value="{% if book['custom_column_' ~ c.id][0].value %}{{book['custom_column_' ~ c.id][0].value|formatdate}}{% endif %}" {% endif %}> - + {% endif %} diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index b3d68cc3..0c2ddf19 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -17,22 +17,22 @@
- +
- - + + - +
- +
- - + + - +
@@ -181,7 +181,7 @@ - +
@@ -191,7 +191,7 @@ - + diff --git a/cps/web.py b/cps/web.py index 78630315..9cffc931 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1080,10 +1080,10 @@ def adv_search_custom_columns(cc, term, q): custom_end = term.get('custom_column_' + str(c.id) + '_end') if custom_start: q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( - db.cc_classes[c.id].value >= custom_start)) + func.datetime(db.cc_classes[c.id].value) >= func.datetime(custom_start))) if custom_end: q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( - db.cc_classes[c.id].value <= custom_end)) + func.datetime(db.cc_classes[c.id].value) <= func.datetime(custom_end))) else: custom_query = term.get('custom_column_' + str(c.id)) if custom_query != '' and custom_query is not None: @@ -1254,8 +1254,8 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): author_name = term.get("author_name") book_title = term.get("book_title") publisher = term.get("publisher") - pub_start = term.get("Publishstart") - pub_end = term.get("Publishend") + pub_start = term.get("publishstart") + pub_end = term.get("publishend") rating_low = term.get("ratinghigh") rating_high = term.get("ratinglow") description = term.get("comment") @@ -1310,9 +1310,9 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): if book_title: q = q.filter(func.lower(db.Books.title).ilike("%" + book_title + "%")) if pub_start: - q = q.filter(db.Books.pubdate >= pub_start) + q = q.filter(func.datetime(db.Books.pubdate) > func.datetime(pub_start)) if pub_end: - q = q.filter(db.Books.pubdate <= pub_end) + q = q.filter(func.datetime(db.Books.pubdate) < func.datetime(pub_end)) q = adv_search_read_status(q, read_status) if publisher: q = q.filter(db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + publisher + "%"))) From dafc68f0493dca74b387db79cf110e911f25273d Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 16 May 2021 09:03:47 +0200 Subject: [PATCH 2/2] Updated requirements --- optional-requirements.txt | 14 +++++++------- requirements.txt | 8 ++++---- setup.cfg | 31 +++++++++++++++++-------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index eb67f59b..4273ec24 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -1,15 +1,15 @@ # GDrive Integration gevent>20.6.0,<21.2.0 -greenlet>=0.4.17,<1.1.0 -httplib2>=0.9.2,<0.18.0 +greenlet>=0.4.17,<1.2.0 +httplib2>=0.9.2,<0.20.0 oauth2client>=4.0.0,<4.1.4 uritemplate>=3.0.0,<3.1.0 pyasn1-modules>=0.0.8,<0.3.0 pyasn1>=0.1.9,<0.5.0 -PyDrive2>=1.3.1,<1.8.0 +PyDrive2>=1.3.1,<1.9.0 PyYAML>=3.12 -rsa>=3.4.2,<4.1.0 -six>=1.10.0,<1.15.0 +rsa>=3.4.2,<4.8.0 +six>=1.10.0,<1.17.0 # Gdrive and Gmail integration google-api-python-client>=1.7.11,<2.1.0 @@ -26,7 +26,7 @@ python-ldap>=3.0.0,<3.4.0 Flask-SimpleLDAP>=1.4.0,<1.5.0 #oauth -Flask-Dance>=1.4.0,<4.1.0 +Flask-Dance>=2.0.0,<5.1.0 SQLAlchemy-Utils>=0.33.5,<0.38.0 # extracting metadata @@ -34,7 +34,7 @@ lxml>=3.8.0,<4.7.0 rarfile>=2.7 # other -natsort>=2.2.0,<7.1.0 +natsort>=2.2.0,<7.2.0 comicapi>= 2.2.0,<2.3.0 #Kobo integration diff --git a/requirements.txt b/requirements.txt index 8f273296..b29d3b99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ -Babel>=1.3, <2.9 +Babel>=1.3, <3.0 Flask-Babel>=0.11.1,<2.1.0 Flask-Login>=0.3.2,<0.5.1 Flask-Principal>=0.3.2,<0.5.1 backports_abc>=0.4 -Flask>=1.0.2,<1.2.0 +Flask>=1.0.2,<2.1.0 iso-639>=0.4.5,<0.5.0 PyPDF3>=1.0.0,<1.0.4 pytz>=2016.10 requests>=2.11.1,<2.25.0 -SQLAlchemy>=1.3.0,<1.4.0 # oauth fails on 1.4+ due to import problems in flask_dance +SQLAlchemy>=1.3.0,<1.5.0 tornado>=4.1,<6.2 Wand>=0.4.4,<0.7.0 -unidecode>=0.04.19,<1.2.0 +unidecode>=0.04.19,<1.3.0 diff --git a/setup.cfg b/setup.cfg index 8266391c..23c4e60b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,35 +34,38 @@ console_scripts = [options] include_package_data = True install_requires = - Babel>=1.3, <2.9 + Babel>=1.3, <3.0 Flask-Babel>=0.11.1,<2.1.0 Flask-Login>=0.3.2,<0.5.1 Flask-Principal>=0.3.2,<0.5.1 backports_abc>=0.4 - Flask>=1.0.2,<1.2.0 + Flask>=1.0.2,<2.1.0 iso-639>=0.4.5,<0.5.0 PyPDF3>=1.0.0,<1.0.4 pytz>=2016.10 requests>=2.11.1,<2.25.0 - SQLAlchemy>=1.3.0,<1.4.0 + SQLAlchemy>=1.3.0,<1.5.0 tornado>=4.1,<6.2 Wand>=0.4.4,<0.7.0 - unidecode>=0.04.19,<1.2.0 + unidecode>=0.04.19,<1.3.0 [options.extras_require] gdrive = - google-api-python-client>=1.7.11,<1.13.0 + google-api-python-client>=1.7.11,<2.1.0 gevent>20.6.0,<21.2.0 - greenlet>=0.4.17,<1.1.0 - httplib2>=0.9.2,<0.18.0 + greenlet>=0.4.17,<1.2.0 + httplib2>=0.9.2,<0.20.0 oauth2client>=4.0.0,<4.1.4 uritemplate>=3.0.0,<3.1.0 pyasn1-modules>=0.0.8,<0.3.0 pyasn1>=0.1.9,<0.5.0 - PyDrive2>=1.3.1,<1.8.0 + PyDrive2>=1.3.1,<1.9.0 PyYAML>=3.12 - rsa>=3.4.2,<4.1.0 - six>=1.10.0,<1.15.0 + rsa>=3.4.2,<4.8.0 + six>=1.10.0,<1.17.0 +gmail = + google-auth-oauthlib>=0.4.3,<0.5.0 + google-api-python-client>=1.7.11,<2.1.0 goodreads = goodreads>=0.3.2,<0.4.0 python-Levenshtein>=0.12.0,<0.13.0 @@ -70,14 +73,14 @@ ldap = python-ldap>=3.0.0,<3.4.0 Flask-SimpleLDAP>=1.4.0,<1.5.0 oauth = - Flask-Dance>=1.4.0,<3.1.0 - SQLAlchemy-Utils>=0.33.5,<0.37.0 + Flask-Dance>=2.0.0,<5.1.0 + SQLAlchemy-Utils>=0.33.5,<0.38.0 metadata = lxml>=3.8.0,<4.7.0 rarfile>=2.7 comics = - natsort>=2.2.0,<7.1.0 - comicapi>= 2.1.3,<2.2.0 + natsort>=2.2.0,<7.2.0 + comicapi>= 2.2.0,<2.3.0 kobo = jsonschema>=3.2.0,<3.3.0