From 961718627971bdeea8ca5d3919020cde8ec3f3cb Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Wed, 6 Jan 2021 23:26:10 +1100 Subject: [PATCH] TODO 3 and 4 finished. removing parent or sub books from series handled --- README | 5 ----- main.py | 25 +++++++++++++++++++---- templates/book.html | 48 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/README b/README index ba46f18..95c0abe 100644 --- a/README +++ b/README @@ -31,11 +31,6 @@ python3 main.py MAYBE-1: when moving a book in a series (which is part of 2 series), do we pop-up offer to move parent/child series orders as well to match (think Thomas Covenant) #### TODOS (next 22): -TODO-3: when remove a Parent book from a series (condition in code marked with BUG): - - popup with: remove all sub books from series too? -TODO-4: removing a subbook from a series (condition in code marked with BUG) - - dont allow it & say remove sub book form parent book before we can act on this. OR: - - popup with: this is a subbook, you want to remove the parent & all its sub books from the series? TODO-5: should deleting really just ask if want to mark it as SOLD? TODO-8: show books on shelf list TODO-9: show books to buy view / printable diff --git a/main.py b/main.py index cbf6868..360ff0a 100644 --- a/main.py +++ b/main.py @@ -444,6 +444,7 @@ def new_book(): def book(id): book_form = BookForm(request.form) page_title='Edit Book' + CheckSeriesChange=None if request.method == 'POST': if 'delete' in request.form: book = Book.query.get(id) @@ -502,16 +503,20 @@ def book(id): book.author.append( Author.query.get( request.form[el] ) ) still_in_series=0 + still_in_series_sid=99999 if book.IsParent(): for field in request.form: if 'bsl-book_num-' in field and field != 'bsl-book_num-NUM' and request.form[field] == 'PARENT': + cnt=int(re.findall( '\d+', field )[0]) + print("cnt={}".format(cnt)) + still_in_series_sid=request.form['bsl-series_id-{}'.format(cnt)] still_in_series=1 if book.IsChild() or (book.IsParent() and not still_in_series): if book.IsParent(): - print ( "BUG: Houston we have a problem, need to deal with parent book being moved out of series, without its subbooks... (IGNORING series change)" ) + CheckSeriesChange={'type':'parent', 'pid': book.id, 'bid': book.id} else: - print ( "BUG: Houston we have a problem, need to deal with child book being moved out of series, without its parent... (IGNORING series change)" ) + CheckSeriesChange={'type':'child', 'pid': book.parent[0].id, 'bid': book.id } else: # delete all bsls db.engine.execute("delete from book_series_link where book_id = {}".format( book.id ) ) @@ -544,8 +549,7 @@ def book(id): genre_list = GetGenres() book_s = book_schema.dump(book) - print( "parent={}".format(book.parent )) - return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage(), poss_series_list=ListOfSeriesWithMissingBooks() ) + return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage(), poss_series_list=ListOfSeriesWithMissingBooks(), CheckSeriesChange=CheckSeriesChange) def GetCount( what, where ): st="select count(id) as count from book where " @@ -603,6 +607,19 @@ def add_books_to_loan(id): print ("NOT SURE WHAT TO DO if we dont want output" ) return redirect("/loan/{}".format(id)) +@app.route("/rem_parent_books_from_series/", methods=["POST"]) +def rem_parent_books_from_series(pid): + print ("pid={}".format(pid) ) + try: + db.engine.execute("delete from book_series_link where book_id in ( select sub_book_id from book_sub_book_link where book_id = {} ) ".format( pid )) + db.engine.execute("delete from book_series_link where book_id = {}".format( pid )) + db.session.commit() + except SQLAlchemyError as e: + st.SetAlert("danger") + st.SetMessage("Failed to delete parent & sub books from ALL series! -- {}".format( e.orig )) + print ("NOT SURE WHAT TO DO if we dont want output - can we just return a 200?" ) + return redirect("/") + @app.route("/", methods=["GET"]) def main_page(): return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage()) diff --git a/templates/book.html b/templates/book.html index 02e8e9d..1f7d480 100644 --- a/templates/book.html +++ b/templates/book.html @@ -22,6 +22,46 @@ {% endblock script_content %} {% endif %}