diff --git a/README b/README index 1ed644a..466bf92 100644 --- a/README +++ b/README @@ -31,9 +31,9 @@ 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: +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 +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? diff --git a/main.py b/main.py index 3de473e..cbf6868 100644 --- a/main.py +++ b/main.py @@ -231,7 +231,7 @@ book_schema = BookSchema() @app.route("/search", methods=["POST"]) def search(): if 'InDBox' in request.form: - # removes already loaned books from list of books to loan out + # removes already loaned books from list of books to loan out books = Book.query.outerjoin(Book_Loan_Link).filter(Book.title.ilike("%{}%".format(request.form['term'])),Book_Loan_Link.loan_id==None).all() InDBox=1 else: @@ -501,19 +501,32 @@ def book(id): if 'author-' in el: book.author.append( Author.query.get( request.form[el] ) ) - print( "DEBUG: bsl={}".format( book.bsl )) - # delete all bsls - db.engine.execute("delete from book_series_link where book_id = {}".format( book.id ) ) - cnt=1 - for field in request.form: - if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM': - cnt=int(re.findall( '\d+', field )[0]) - sql="insert into book_series_link (book_id, series_id, book_num) values ( {}, {}, {} )".format( request.form['bsl-book_id-{}'.format(cnt)], request.form['bsl-series_id-{}'.format(cnt)], request.form['bsl-book_num-{}'.format(cnt)]) - db.engine.execute( sql ) - cnt=cnt+1 + still_in_series=0 + 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': + 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)" ) + 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)" ) + else: + # delete all bsls + db.engine.execute("delete from book_series_link where book_id = {}".format( book.id ) ) + + cnt=1 + for field in request.form: + if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM': + cnt=int(re.findall( '\d+', field )[0]) + if book.IsParent(): + sql="insert into book_series_link (book_id, series_id) values ( {}, {} )".format( request.form['bsl-book_id-{}'.format(cnt)], request.form['bsl-series_id-{}'.format(cnt)] ) + else: + sql="insert into book_series_link (book_id, series_id, book_num) values ( {}, {}, {} )".format( request.form['bsl-book_id-{}'.format(cnt)], request.form['bsl-series_id-{}'.format(cnt)], request.form['bsl-book_num-{}'.format(cnt)]) + db.engine.execute( sql ) + cnt=cnt+1 - ## TODO: - # what about series?, subbooks?, loan?, etc. db.session.commit() st.SetMessage( "Successfully Updated Book (id={})".format(id) ) else: @@ -531,7 +544,7 @@ def book(id): genre_list = GetGenres() book_s = book_schema.dump(book) - print( book.parent ) + 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() ) def GetCount( what, where ): diff --git a/templates/book.html b/templates/book.html index 300275e..02e8e9d 100644 --- a/templates/book.html +++ b/templates/book.html @@ -249,6 +249,7 @@ function AddAuthorToBook(num) { Book {{ SeriesBookNum( s.id, books.id ) }} of {{s.num_books}} in {{s.title}} {% else %} + {% set hiddens.txt=hiddens.txt+"".format(loop.index) %}