fix comment

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-09 13:01:05 +03:00
parent cc18360279
commit e439c2e8fb
1 changed files with 53 additions and 54 deletions

View File

@ -1341,68 +1341,67 @@ def comment_delete(
interpretation_id: int, interpretation_id: int,
sub_collection_id: int | None = None, sub_collection_id: int | None = None,
): ):
form = f.DeleteCommentForm() book: m.Book = db.session.get(m.Book, book_id)
if form.validate_on_submit():
book: m.Book = db.session.get(m.Book, book_id)
comment_id = form.comment_id.data
if not book or book.owner != current_user 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_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id) if not book or book.owner != current_user or book.is_deleted:
if not collection or collection.is_deleted: log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
log(log.WARNING, "Collection with id [%s] not found", collection_id) flash("You are not owner of this book!", "danger")
flash("Collection not found", "danger") return redirect(url_for("book.my_books"))
return redirect(url_for("book.collection_view", book_id=book_id))
if sub_collection_id: collection: m.Collection = db.session.get(m.Collection, collection_id)
sub_collection: m.Collection = db.session.get( if not collection or collection.is_deleted:
m.Collection, sub_collection_id 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))
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,
) )
if not sub_collection or sub_collection.is_deleted: flash("SubCollection not found", "danger")
log( return redirect(
log.WARNING, url_for(
"Sub_collection with id [%s] not found", "book.sub_collection_view",
sub_collection_id, book_id=book_id,
) collection_id=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( redirect_url = url_for(
"book.qa_view", "book.qa_view",
book_id=book_id, book_id=book_id,
collection_id=collection_id, collection_id=collection_id,
sub_collection_id=sub_collection_id, sub_collection_id=sub_collection_id,
section_id=section_id, section_id=section_id,
interpretation_id=interpretation_id, interpretation_id=interpretation_id,
) )
section: m.Section = db.session.get(m.Section, section_id) section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted: if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id) log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger") flash("Section not found", "danger")
return redirect(redirect_url) return redirect(redirect_url)
interpretation: m.Interpretation = db.session.get( interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id m.Interpretation, interpretation_id
) )
if not interpretation or interpretation.is_deleted: if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id) log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger") flash("Interpretation not found", "danger")
return redirect(redirect_url) return redirect(redirect_url)
comment: m.Comment = db.session.get(m.Comment, comment_id) form = f.DeleteCommentForm()
if not comment or comment.is_deleted: comment_id = form.comment_id.data
log(log.WARNING, "Comment with id [%s] not found", comment_id) comment: m.Comment = db.session.get(m.Comment, comment_id)
flash("Comment not found", "danger") if not comment or comment.is_deleted:
return redirect(redirect_url) log(log.WARNING, "Comment with id [%s] not found", comment_id)
flash("Comment not found", "danger")
return redirect(redirect_url)
if form.validate_on_submit():
comment.is_deleted = True comment.is_deleted = True
log(log.INFO, "Delete comment [%s]", comment) log(log.INFO, "Delete comment [%s]", comment)
comment.save() comment.save()