diff --git a/app/templates/book/delete_comment_modal.html b/app/templates/book/delete_comment_modal.html index e91abc9..b2f0886 100644 --- a/app/templates/book/delete_comment_modal.html +++ b/app/templates/book/delete_comment_modal.html @@ -3,11 +3,7 @@
{{ form_hidden_tag() }} diff --git a/app/templates/book/edit_comment_modal.html b/app/templates/book/edit_comment_modal.html index 6faca52..72bf071 100644 --- a/app/templates/book/edit_comment_modal.html +++ b/app/templates/book/edit_comment_modal.html @@ -3,11 +3,7 @@
{{ form_hidden_tag() }} diff --git a/app/views/book/comment.py b/app/views/book/comment.py index 523fc1d..41ea4e0 100644 --- a/app/views/book/comment.py +++ b/app/views/book/comment.py @@ -14,58 +14,22 @@ from .bp import bp @bp.route( - "/////create_comment", - methods=["POST"], -) -@bp.route( - ( - "////" - "//create_comment" - ), + "///create_comment", methods=["POST"], ) @login_required def create_comment( book_id: int, - collection_id: int, - section_id: int, interpretation_id: int, - sub_collection_id: int | None = None, ): book: m.Book = db.session.get(m.Book, book_id) if not book or book.is_deleted: log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book) flash("You are not owner of this book!", "danger") return redirect(url_for("book.my_library")) - - collection: m.Collection = db.session.get(m.Collection, collection_id) - if not collection or collection.is_deleted: - log(log.WARNING, "Collection with id [%s] not found", collection_id) - flash("Collection not found", "danger") - return redirect(url_for("book.collection_view", book_id=book_id)) - - sub_collection = None - if sub_collection_id: - sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id) - if not sub_collection or sub_collection.is_deleted: - log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id) - flash("SubCollection not found", "danger") - return redirect( - url_for( - "book.sub_collection_view", - book_id=book_id, - collection_id=collection_id, - ) - ) - redirect_url = url_for( "book.qa_view", book_id=book_id, interpretation_id=interpretation_id ) - section: m.Section = db.session.get(m.Section, section_id) - if not section or section.is_deleted: - log(log.WARNING, "Section with id [%s] not found", section_id) - flash("Section not found", "danger") - return redirect(redirect_url) interpretation: m.Interpretation = db.session.get( m.Interpretation, interpretation_id @@ -90,9 +54,8 @@ def create_comment( log( log.INFO, - "Create comment for interpretation [%s]. Section: [%s]", + "Create comment for interpretation [%s].", interpretation, - section, ) comment.save() @@ -112,25 +75,18 @@ def create_comment( @bp.route( - "/////comment_delete", - methods=["POST"], -) -@bp.route( - ( - "////" - "//comment_delete" - ), + "///comment_delete", methods=["POST"], ) @register_book_verify_route(bp.name) @login_required def comment_delete( book_id: int, - collection_id: int, - section_id: int, interpretation_id: int, - sub_collection_id: int | None = None, ): + redirect_url = url_for( + "book.qa_view", book_id=book_id, interpretation_id=interpretation_id + ) form = f.DeleteCommentForm() comment_id = form.comment_id.data comment: m.Comment = db.session.get(m.Comment, comment_id) @@ -142,40 +98,29 @@ def comment_delete( comment.save() flash("Success!", "success") - return redirect( - url_for( - "book.qa_view", book_id=book_id, interpretation_id=interpretation_id - ) - ) + return redirect(redirect_url) + flash("Invalid id!", "danger") return redirect( url_for( - "book.sub_collection_view", + "book.collection_view", book_id=book_id, - collection_id=collection_id, ) ) @bp.route( - "/////comment_edit", - methods=["POST"], -) -@bp.route( - ( - "////" - "//comment_edit" - ), + "///comment_edit", methods=["POST"], ) @register_book_verify_route(bp.name) @login_required def comment_edit( book_id: int, - collection_id: int, - section_id: int, interpretation_id: int, - sub_collection_id: int | None = None, ): + redirect_url = url_for( + "book.qa_view", book_id=book_id, interpretation_id=interpretation_id + ) form = f.EditCommentForm() if form.validate_on_submit(): @@ -192,15 +137,12 @@ def comment_edit( comment.save() flash("Success!", "success") - return redirect( - url_for( - "book.qa_view", book_id=book_id, interpretation_id=interpretation_id - ) - ) + return redirect(redirect_url) + flash("Invalid id!", "danger") + return redirect( url_for( - "book.sub_collection_view", + "book.collection_view", book_id=book_id, - collection_id=collection_id, ) ) diff --git a/tests/test_book.py b/tests/test_book.py index 6f4798f..197129c 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -1015,9 +1015,8 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner): comment_text = "Some comment text" response: Response = client.post( - f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/{interpretation.id}/create_comment", + f"/book/{book.id}/{interpretation.id}/create_comment", data=dict( - section_id=section_in_subcollection.id, text=comment_text, interpretation_id=interpretation.id, ), @@ -1036,9 +1035,8 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner): # edit response: Response = client.post( - f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/{interpretation.id}/comment_edit", + f"/book/{book.id}/{interpretation.id}/comment_edit", data=dict( - section_id=section_in_subcollection.id, text=new_text, interpretation_id=interpretation.id, comment_id=comment.id, @@ -1054,9 +1052,8 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner): # delete response: Response = client.post( - f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/{interpretation.id}/comment_delete", + f"/book/{book.id}/{interpretation.id}/comment_delete", data=dict( - section_id=section_in_subcollection.id, text=comment_text, interpretation_id=interpretation.id, comment_id=comment.id, diff --git a/tests/test_tag.py b/tests/test_tag.py index f0616b2..b6180bc 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -83,13 +83,12 @@ def test_create_tags_on_comment_create_and_edit(client: FlaskClient): create_test_book(user.id, 1) book = db.session.get(m.Book, 1) - collection = db.session.get(m.Collection, 1) section = db.session.get(m.Section, 1) interpretation = db.session.get(m.Interpretation, 1) tags = "[tag1] [tag2] [tag3]" response: Response = client.post( - f"/book/{book.id}/{collection.id}/{section.id}/{interpretation.id}/create_comment", + f"/book/{book.id}/{interpretation.id}/create_comment", data=dict( section_id=section.id, text="some text" + tags, @@ -116,7 +115,7 @@ def test_create_tags_on_comment_create_and_edit(client: FlaskClient): tags = "[tag1] [tag5] [tag7]" response: Response = client.post( - f"/book/{book.id}/{collection.id}/{section.id}/{interpretation.id}/comment_edit", + f"/book/{book.id}/{interpretation.id}/comment_edit", data=dict(text="some text" + tags, comment_id=comment.id), follow_redirects=True, ) @@ -143,14 +142,13 @@ def test_create_tags_on_interpretation_create_and_edit(client: FlaskClient): create_test_book(user.id, 1) book = db.session.get(m.Book, 1) - collection = db.session.get(m.Collection, 1) section = db.session.get(m.Section, 1) tags = "[tag1] [tag2] [tag3]" text_1 = "Test Interpretation #1 Text" response: Response = client.post( - f"/book/{book.id}/{collection.id}/{section.id}/create_interpretation", + f"/book/{book.id}/{section.id}/create_interpretation", data=dict(section_id=section.id, text=text_1 + tags), follow_redirects=True, )