TODO 3 and 4 finished. removing parent or sub books from series handled
This commit is contained in:
25
main.py
25
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/<pid>", 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())
|
||||
|
||||
Reference in New Issue
Block a user