diff --git a/cps/editbooks.py b/cps/editbooks.py index 4d195eb7..d5fe580c 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -60,6 +60,7 @@ from .tasks.upload import TaskUpload from .render_template import render_title_template from .usermanagement import login_required_if_no_ano from .kobo_sync_status import change_archived_books +from .redirect import get_redirect_location editbook = Blueprint('edit-book', __name__) @@ -96,7 +97,7 @@ def delete_book_from_details(book_id): @editbook.route("/delete//", methods=["POST"]) @login_required def delete_book_ajax(book_id, book_format): - return delete_book_from_table(book_id, book_format, False) + return delete_book_from_table(book_id, book_format, False, request.form.to_dict().get('location', "")) @editbook.route("/admin/book/", methods=['GET']) @@ -823,7 +824,7 @@ def delete_whole_book(book_id, book): calibre_db.session.query(db.Books).filter(db.Books.id == book_id).delete() -def render_delete_book_result(book_format, json_response, warning, book_id): +def render_delete_book_result(book_format, json_response, warning, book_id, location=""): if book_format: if json_response: return json.dumps([warning, {"location": url_for("edit-book.show_edit_book", book_id=book_id), @@ -835,16 +836,16 @@ def render_delete_book_result(book_format, json_response, warning, book_id): return redirect(url_for('edit-book.show_edit_book', book_id=book_id)) else: if json_response: - return json.dumps([warning, {"location": url_for('web.index'), + return json.dumps([warning, {"location": get_redirect_location(location, "web.index"), "type": "success", "format": book_format, "message": _('Book Successfully Deleted')}]) else: flash(_('Book Successfully Deleted'), category="success") - return redirect(url_for('web.index')) + return redirect(get_redirect_location(location, "web.index")) -def delete_book_from_table(book_id, book_format, json_response): +def delete_book_from_table(book_id, book_format, json_response, location=""): warning = {} if current_user.role_delete_books(): book = calibre_db.get_book(book_id) @@ -891,7 +892,7 @@ def delete_book_from_table(book_id, book_format, json_response): else: # book not found log.error('Book with id "%s" could not be deleted: not found', book_id) - return render_delete_book_result(book_format, json_response, warning, book_id) + return render_delete_book_result(book_format, json_response, warning, book_id, location) message = _("You are missing permissions to delete books") if json_response: return json.dumps({"location": url_for("edit-book.show_edit_book", book_id=book_id), diff --git a/cps/helper.py b/cps/helper.py index 33da0f37..0cc7362c 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -692,15 +692,15 @@ def valid_password(check_password): if config.config_password_policy: verify = "" if config.config_password_min_length > 0: - verify += "^(?=.{" + str(config.config_password_min_length) + ",}$)" + verify += r"^(?=.{" + str(config.config_password_min_length) + ",}$)" if config.config_password_number: - verify += "(?=.*?\d)" + verify += r"(?=.*?\d)" if config.config_password_lower: - verify += "(?=.*?[a-z])" + verify += r"(?=.*?[a-z])" if config.config_password_upper: - verify += "(?=.*?[A-Z])" + verify += r"(?=.*?[A-Z])" if config.config_password_special: - verify += "(?=.*?[^A-Za-z\s0-9])" + verify += r"(?=.*?[^A-Za-z\s0-9])" match = re.match(verify, check_password) if not match: raise Exception(_("Password doesn't comply with password validation rules")) @@ -1039,7 +1039,7 @@ def check_calibre(calibre_location): binaries_available = [os.path.isfile(binary_path) for binary_path in supported_binary_paths] binaries_executable = [os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths] if all(binaries_available) and all(binaries_executable): - values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') + values = [process_wait([binary_path, "--version"], pattern=r'\(calibre (.*)\)') for binary_path in supported_binary_paths] if all(values): version = values[0].group(1) diff --git a/cps/redirect.py b/cps/redirect.py index 337bb77b..7f504b98 100755 --- a/cps/redirect.py +++ b/cps/redirect.py @@ -44,9 +44,9 @@ def remove_prefix(text, prefix): return "" -def redirect_back(endpoint, **values): - target = request.form.get('next', None) or url_for(endpoint, **values) +def get_redirect_location(next, endpoint, **values): + target = next or url_for(endpoint, **values) adapter = current_app.url_map.bind(urlparse(request.host_url).netloc) if not len(adapter.allowed_methods(remove_prefix(target, request.environ.get('HTTP_X_SCRIPT_NAME',"")))): target = url_for(endpoint, **values) - return redirect(target) + return target diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 34d3bc96..9b7e9290 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -20,7 +20,7 @@ function getPath() { return jsFileLocation.substr(0, jsFileLocation.search("/static/js/libs/jquery.min.js")); // the js folder path } -function postButton(event, action){ +function postButton(event, action, location=""){ event.preventDefault(); var newForm = jQuery('
', { "action": action, @@ -30,7 +30,14 @@ function postButton(event, action){ 'name': 'csrf_token', 'value': $("input[name=\'csrf_token\']").val(), 'type': 'hidden' - })).appendTo('body'); + })).appendTo('body') + if(location !== "") { + newForm.append(jQuery('', { + 'name': 'location', + 'value': location, + 'type': 'hidden' + })).appendTo('body'); + } newForm.submit(); } @@ -212,17 +219,20 @@ $("#delete_confirm").click(function(event) { $( ".navbar" ).after( '
' + '
'+item.message+'
' + '
'); - } }); $("#books-table").bootstrapTable("refresh"); } }); } else { - postButton(event, getPath() + "/delete/" + deleteId); + var loc = sessionStorage.getItem("back"); + if (!loc) { + loc = $(this).data("back"); + } + sessionStorage.removeItem("back"); + postButton(event, getPath() + "/delete/" + deleteId, location=loc); } } - }); //triggered when modal is about to be shown diff --git a/cps/templates/author.html b/cps/templates/author.html index b991e959..3e82161c 100644 --- a/cps/templates/author.html +++ b/cps/templates/author.html @@ -32,7 +32,7 @@
{% for entry in entries %} -
+
@@ -99,7 +99,7 @@

{{_("More by")}} {{ author.name.replace('|',',') }}

@@ -367,4 +367,3 @@ {% endblock %} - diff --git a/cps/templates/index.html b/cps/templates/index.html index 464a1461..b1169e01 100644 --- a/cps/templates/index.html +++ b/cps/templates/index.html @@ -6,7 +6,7 @@

{{_('Discover (Random Books)')}}

{% for entry in random %} -
+
@@ -89,7 +89,7 @@
{% if entries[0] %} {% for entry in entries %} -