From 4745fc0db171beac8ecb0f1aafd9ae615090fd22 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 15 May 2021 07:51:32 +0200 Subject: [PATCH] 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 + "%")))