From 0d07e445dea166cb411f4d8f1d68dbda6af121a6 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 8 Sep 2025 12:05:59 +0200 Subject: [PATCH] Bugfix mass edit books --- cps/editbooks.py | 7 ++++++- cps/helper.py | 12 ++++++------ cps/static/js/table.js | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 40680228..a2c39b9d 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -215,7 +215,8 @@ def table_get_custom_enum(c_id): @edit_required def edit_list_book(param): vals = request.get_json() - ret_value = edit_book_param(param, vals) + multi = vals.get('multi', False) == "True" + ret_value = edit_book_param(param, vals, multi) if isinstance(ret_value, dict): return jsonify(ret_value) else: @@ -369,9 +370,11 @@ def edit_book_param(param, vals, multi=False): if handle_title_on_edit(book, vals.get('value', "")): rename_error = helper.update_dir_structure(book.id, config.get_book_path()) if not rename_error: + calibre_db.session.commit() ret = {"success":True, "newValue":book.title} else: + calibre_db.session.rollback() ret = {"success":False, "msg":rename_error} if multi: out.append(ret) @@ -387,9 +390,11 @@ def edit_book_param(param, vals, multi=False): input_authors, __ = handle_author_on_edit(book, vals['value'], vals.get('checkA', None) == True) rename_error = helper.update_dir_structure(book.id, config.get_book_path(), input_authors[0]) if not rename_error: + calibre_db.session.commit() ret = {"success":True, "newValue":' & '.join([author.replace('|', ',') for author in input_authors])} else: + calibre_db.session.rollback() ret = {"success":False, "msg":rename_error} if multi: out.append(ret) diff --git a/cps/helper.py b/cps/helper.py index eb6bcd25..dd629882 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -471,12 +471,12 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth db_filename, original_filepath, path) - new_path = os.path.join(calibre_path, new_author_dir, new_title_dir).replace('\\', '/') - all_new_name = get_valid_filename(local_book.title, chars=42) + ' - ' \ - + get_valid_filename(new_author, chars=42) - # Book folder already moved, only files need to be renamed - renameerror = rename_all_files_on_change(local_book, new_path, new_path, all_new_name) - + if not error: + new_path = os.path.join(calibre_path, new_author_dir, new_title_dir).replace('\\', '/') + all_new_name = get_valid_filename(local_book.title, chars=42) + ' - ' \ + + get_valid_filename(new_author, chars=42) + # Book folder already moved, only files need to be renamed + renameerror = rename_all_files_on_change(local_book, new_path, new_path, all_new_name) if error or renameerror: return error or renameerror diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 02933db1..a5ac53c2 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -1265,7 +1265,7 @@ function bookCheckboxHeader(CheckboxState, text, field_index) { $.ajax({ method: "post", url: getPath() + "/ajax/editbooks/" + field_index, - data: JSON.stringify({"pk": result, "field_index": field_index, "value": CheckboxState}), + data: JSON.stringify({"pk": result, "field_index": field_index, "value": CheckboxState, multi: "True"}), contentType: "application/json; charset=utf-8", dataType: "json", error: function (data) {