diff --git a/cps/admin.py b/cps/admin.py index 2c32431f..04d9138f 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -590,6 +590,8 @@ def load_dialogtexts(element_id): texts["main"] = _('Are you sure you want to change shelf sync behavior for the selected user(s)?') elif element_id == "db_submit": texts["main"] = _('Are you sure you want to change Calibre library location?') + elif element_id == "btnfullsync": + texts["main"] = _("Are you sure you want delete Calibre-Web's sync database to force a full sync with your Kobo Reader?") return json.dumps(texts) @@ -889,10 +891,18 @@ def list_restriction(res_type, user_id): else: json_dumps = "" js = json.dumps(json_dumps) - response = make_response(js) #.replace("'", '"') + response = make_response(js) response.headers["Content-Type"] = "application/json; charset=utf-8" return response +@admi.route("/ajax/fullsync") +@login_required +def ajax_fullsync(): + count = ub.session.query(ub.KoboSyncedBooks).filter(current_user.id == ub.KoboSyncedBooks.user_id).delete() + message = _("{} sync entries deleted").format(count) + ub.session_commit(message) + return Response(json.dumps([{"type": "success", "message": message}]), mimetype='application/json') + @admi.route("/ajax/pathchooser/") @login_required @@ -1189,13 +1199,13 @@ def _db_configuration_update_helper(): # if db changed -> delete shelfs, delete download books, delete read books, kobo sync... ub.session.query(ub.Downloads).delete() ub.session.query(ub.ArchivedBook).delete() - ub.session.query(ub.ArchivedBook).delete() ub.session.query(ub.ReadBook).delete() ub.session.query(ub.BookShelf).delete() ub.session.query(ub.Bookmark).delete() ub.session.query(ub.KoboReadingState).delete() ub.session.query(ub.KoboStatistics).delete() ub.session.query(ub.KoboSyncedBooks).delete() + ub.session_commit() _config_string(to_save, "config_calibre_dir") calibre_db.update_config(config) if not os.access(os.path.join(config.config_calibre_dir, "metadata.db"), os.W_OK): diff --git a/cps/editbooks.py b/cps/editbooks.py index 31e38d2a..21dc3ba0 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -240,14 +240,14 @@ def modify_identifiers(input_identifiers, db_identifiers, db_session): @editbook.route("/ajax/delete/") @login_required def delete_book_from_details(book_id): - return Response(delete_book(book_id, "", True), mimetype='application/json') + return Response(delete_book_from_table(book_id, "", True), mimetype='application/json') @editbook.route("/delete/", defaults={'book_format': ""}) @editbook.route("/delete//") @login_required def delete_book_ajax(book_id, book_format): - return delete_book(book_id, book_format, False) + return delete_book_from_table(book_id, book_format, False) def delete_whole_book(book_id, book): @@ -317,7 +317,7 @@ def render_delete_book_result(book_format, jsonResponse, warning, book_id): return redirect(url_for('web.index')) -def delete_book(book_id, book_format, jsonResponse): +def delete_book_from_table(book_id, book_format, jsonResponse): warning = {} if current_user.role_delete_books(): book = calibre_db.get_book(book_id) @@ -1254,7 +1254,7 @@ def merge_list_book(): element.format, element.uncompressed_size, to_name)) - delete_book(from_book.id,"", True) + delete_book_from_table(from_book.id,"", True) return json.dumps({'success': True}) return "" diff --git a/cps/kobo.py b/cps/kobo.py index 482eb13a..c5af44fc 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -209,7 +209,7 @@ def HandleSyncRequest(): books = calibre_db.session.execute(changed_entries.limit(SYNC_ITEM_LIMIT)) else: books = changed_entries.limit(SYNC_ITEM_LIMIT) - log.debug("Books to Sync: {}".format(books.count())) + log.debug("Books to Sync: {}".format(len(books.all()))) for book in books: formats = [data.format for data in book.Books.data] if not 'KEPUB' in formats and config.config_kepubifypath and 'EPUB' in formats: diff --git a/cps/static/js/main.js b/cps/static/js/main.js index cf6fbe0d..585d2296 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -517,6 +517,7 @@ $(function() { .on("hidden.bs.modal", function() { $(this).find(".modal-body").html("..."); $("#config_delete_kobo_token").show(); + $("#kobo_full_sync").show(); }); $("#config_delete_kobo_token").click(function() { @@ -530,6 +531,7 @@ $(function() { url: getPath() + "/kobo_auth/deleteauthtoken/" + value, }); $("#config_delete_kobo_token").hide(); + $("#kobo_full_sync").hide(); } ); }); @@ -563,6 +565,33 @@ $(function() { } ); }); + + $("#kobo_full_sync").click(function() { + confirmDialog( + "btnfullsync", + "GeneralDeleteModal", + $(this).data('value'), + function(value){ + path = getPath() + "/ajax/fullsync" + $.ajax({ + method:"get", + url: path, + timeout: 900, + success:function(data) { + data.forEach(function(item) { + if (!jQuery.isEmptyObject(item)) { + $( ".navbar" ).after( '
' + + '
'+item.message+'
' + + '
'); + } + }); + } + }); + } + ); + }); + + $("#user_submit").click(function() { this.closest("form").submit(); }); diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index edecbaf2..e6fbdb74 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -66,6 +66,9 @@ {{_('Create/View')}} +
+ +
{% endif %}
{% for element in sidebar %}