fix (new) BUG where removing a parent book from a series caused error with bsl-book-num missing. Also flagged 2 spots for dealing with removing parent/child books from a series better, and stopped any attempt to for now

This commit is contained in:
2021-01-06 20:39:51 +11:00
parent 47119cf7f8
commit d43dabff9b
3 changed files with 30 additions and 16 deletions

41
main.py
View File

@@ -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 ):