From f78d2245aa2890e9c019b743c85594e1f0e079fb Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 5 Dec 2021 18:48:21 +0100 Subject: [PATCH] Fixes from testrun --- cps/editbooks.py | 25 ++++++++++++++++++------- cps/templates/book_table.html | 4 +++- cps/web.py | 26 +++++++++++++++++++++----- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 9c942b52..dbb14f79 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -718,8 +718,6 @@ def handle_author_on_edit(book, author_name, update_stored=True): if input_authors == ['']: input_authors = [_(u'Unknown')] # prevent empty Author - # ToDo: Falsch es kann auch sein das der 2. Author in der Liste umbenannt wurde, - # man müsste für alle Authoren schauen renamed = list() for in_aut in input_authors: renamed_author = calibre_db.session.query(db.Authors).filter(db.Authors.name == in_aut).first() @@ -923,6 +921,18 @@ def prepare_authors_on_upload(title, authr): if input_authors == ['']: input_authors = [_(u'Unknown')] # prevent empty Author + renamed = list() + for in_aut in input_authors: + renamed_author = calibre_db.session.query(db.Authors).filter(db.Authors.name == in_aut).first() + if renamed_author and in_aut != renamed_author.name: + renamed.append(renamed_author.name) + all_books = calibre_db.session.query(db.Books) \ + .filter(db.Books.authors.any(db.Authors.name == renamed_author.name)).all() + sorted_renamed_author = helper.get_sorted_author(renamed_author.name) + sorted_old_author = helper.get_sorted_author(in_aut) + for one_book in all_books: + one_book.author_sort = one_book.author_sort.replace(sorted_renamed_author, sorted_old_author) + sort_authors_list = list() db_author = None for inp in input_authors: @@ -939,13 +949,13 @@ def prepare_authors_on_upload(title, authr): sort_author = stored_author.sort sort_authors_list.append(sort_author) sort_authors = ' & '.join(sort_authors_list) - return sort_authors, input_authors, db_author + return sort_authors, input_authors, db_author, renamed def create_book_on_upload(modif_date, meta): title = meta.title authr = meta.author - sort_authors, input_authors, db_author = prepare_authors_on_upload(title, authr) + sort_authors, input_authors, db_author, renamed_authors = prepare_authors_on_upload(title, authr) title_dir = helper.get_valid_filename(title) author_dir = helper.get_valid_filename(db_author.name) @@ -987,7 +997,7 @@ def create_book_on_upload(modif_date, meta): # flush content, get db_book.id available calibre_db.session.flush() - return db_book, input_authors, title_dir + return db_book, input_authors, title_dir, renamed_authors def file_handling_on_upload(requested_file): # check if file extension is correct @@ -1049,7 +1059,7 @@ def upload(): if error: return error - db_book, input_authors, title_dir = create_book_on_upload(modif_date, meta) + db_book, input_authors, title_dir, renamed_authors = create_book_on_upload(modif_date, meta) # Comments needs book id therefore only possible after flush modif_date |= edit_book_comments(Markup(meta.description).unescape(), db_book) @@ -1061,7 +1071,8 @@ def upload(): config.config_calibre_dir, input_authors[0], meta.file_path, - title_dir + meta.extension.lower()) + title_dir + meta.extension.lower(), + renamed_author=renamed_authors) move_coverfile(meta, db_book) diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 92c8a2f5..c842811b 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -71,7 +71,9 @@ {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }} {{_('Comments')}} - {{ book_checkbox_row('is_archived', _('Archiv Status'), false)}} + {% if g.user.check_visibility(32768) %} + {{ book_checkbox_row('is_archived', _('Archiv Status'), false)}} + {% endif %} {{ book_checkbox_row('read_status', _('Read Status'), false)}} {% for c in cc %} {% if c.datatype == "int" %} diff --git a/cps/web.py b/cps/web.py index af5401d8..2419c61b 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1309,7 +1309,24 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): cc = get_cc_columns(filter_config_custom_read=True) calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase) - q = calibre_db.session.query(db.Books).outerjoin(db.books_series_link, db.Books.id == db.books_series_link.c.book)\ + if not config.config_read_column: + query = (calibre_db.session.query(db.Books, ub.ArchivedBook.is_archived, ub.ReadBook).select_from(db.Books) + .outerjoin(ub.ReadBook, and_(db.Books.id == ub.ReadBook.book_id, + int(current_user.id) == ub.ReadBook.user_id))) + else: + try: + read_column = cc[config.config_read_column] + query = (calibre_db.session.query(db.Books, ub.ArchivedBook.is_archived, read_column.value) + .select_from(db.Books) + .outerjoin(read_column, read_column.book == db.Books.id)) + except (KeyError, AttributeError): + log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column) + # Skip linking read column + query = calibre_db.session.query(db.Books, ub.ArchivedBook.is_archived, None) + query = query.outerjoin(ub.ArchivedBook, and_(db.Books.id == ub.ArchivedBook.book_id, + int(current_user.id) == ub.ArchivedBook.user_id)) + + q = query.outerjoin(db.books_series_link, db.Books.id == db.books_series_link.c.book)\ .outerjoin(db.Series)\ .filter(calibre_db.common_filters(True)) @@ -1373,7 +1390,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): rating_high, rating_low, read_status) - q = q.filter() + # q = q.filter() if author_name: q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_name + "%"))) if book_title: @@ -1404,7 +1421,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): q = q.order_by(*sort).all() flask_session['query'] = json.dumps(term) - ub.store_ids(q) + ub.store_combo_ids(q) result_count = len(q) if offset is not None and limit is not None: offset = int(offset) @@ -1413,7 +1430,7 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): else: offset = 0 limit_all = result_count - entries = calibre_db.order_authors(q[offset:limit_all], True) + entries = calibre_db.order_authors(q[offset:limit_all], list_return=True, combined=True) return render_title_template('search.html', adv_searchterm=searchterm, pagination=pagination, @@ -1423,7 +1440,6 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): order=order[1]) - @web.route("/advsearch", methods=['GET']) @login_required_if_no_ano def advanced_search_form():