From 6d97df44e4ad3cc164f0087e34c1bf86d99e7bd4 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 2 Jan 2021 19:10:52 +1100 Subject: [PATCH] TODO-2 completed, can remove a subbook from parent --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 0d7af41..4cd44b5 100644 --- a/main.py +++ b/main.py @@ -352,7 +352,15 @@ def subbooks_for_book(id): ################################################################################ @app.route("/remove_subbook", methods=["POST"]) def remove_sub_book(): - return redirect( '/book/{}'.format(request.form['rem_sub_parent_id']) ) + print("DDP: ADD SQL HERE TO DO THE DELETE - try/except") + try: + db.engine.execute("delete from book_sub_book_link where book_id = {} and sub_book_id = {}".format( request.form['rem_sub_parent_id'], request.form['rem_sub_sub_book_id']) ) + db.session.commit() + return redirect( '/book/{}'.format(request.form['rem_sub_parent_id']) ) + except SQLAlchemyError as e: + st.SetAlert( "danger" ) + st.SetMessage( e.orig ) + return redirect( '/book/{}'.format(request.form['rem_sub_sub_book_id']) ) ################################################################################ # /book -> GET/POST -> creates a new book and when created, takes you back to @@ -438,7 +446,6 @@ def book(id): db.session.commit() except SQLAlchemyError as e: st.SetAlert( "danger" ) - print("actual sql alchemy error") st.SetMessage( e.orig ) return redirect( '/book/{}'.format(id) ) except Exception as e: