fix deleting of users_books

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-12 12:00:54 +03:00
parent 4faf54e652
commit e9af3f86de
5 changed files with 145966 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,9 @@ bp = Blueprint("home", __name__, url_prefix="/home")
@bp.route("/", methods=["GET"]) @bp.route("/", methods=["GET"])
def get_all(): def get_all():
books: m.Book = m.Book.query.order_by(m.Book.id).limit(5) books: m.Book = (
m.Book.query.filter_by(is_deleted=False).order_by(m.Book.id).limit(5)
)
interpretations = ( interpretations = (
db.session.query( db.session.query(
m.Interpretation, m.Interpretation,

View File

@ -102,10 +102,12 @@ def create():
@login_required @login_required
def profile_delete(): def profile_delete():
user: m.User = db.session.get(m.User, current_user.id) user: m.User = db.session.get(m.User, current_user.id)
logout_user() for book in user.books:
book.is_deleted = True
user.is_deleted = True user.is_deleted = True
user.save()
log(log.INFO, "User deleted. User: [%s]", user) log(log.INFO, "User deleted. User: [%s]", user)
user.save()
logout_user()
flash("User deleted!", "success") flash("User deleted!", "success")
return redirect(url_for("home.get_all")) return redirect(url_for("home.get_all"))

View File

@ -117,3 +117,19 @@ def test_profile(client):
follow_redirects=True, follow_redirects=True,
) )
assert b"This field is required." in res2.data assert b"This field is required." in res2.data
book = m.Book(
label="Book label",
about="Book about",
user_id=user.id,
)
book.save()
assert book
# delete_profile
res = client.post(
"/user/profile_delete",
follow_redirects=True,
)
assert res
assert user.is_deleted
assert user.books[0].is_deleted