TODO-6 (add books to loan) is now complete, so loans are now fully functional... the whole pybook is now at least functional, more features/validation to come :)

This commit is contained in:
2021-01-04 22:28:35 +11:00
parent 6ff3d13713
commit 336ae4b67f
6 changed files with 60 additions and 10 deletions

23
main.py
View File

@@ -561,18 +561,31 @@ def stats():
@app.route("/rem_books_from_loan/<id>", methods=["POST"])
def rem_books_from_loan(id):
print( "rem_books_from_loan for loan: {}".format( id ) )
for field in request.form:
rem_id=int(re.findall( '\d+', field )[0])
print( "field: {} -- so removing book id: {}".format( field, rem_id ) )
try:
db.engine.execute("delete from book_loan_link where book_id = {} and loan_id = {}".format( rem_id, id ))
db.session.commit()
except:
except SQLAlchemyError as e:
st.SetAlert("danger")
st.SetMessage("Failed to remove books from loan!")
st.SetMessage("Failed to remove books from loan! -- {}".format( e.orig ))
print( "now redirect to /loan/{}".format(id) )
print ("NOT SURE WHAT TO DO if we dont want output" )
return redirect("/loan/{}".format(id))
@app.route("/add_books_to_loan/<id>", methods=["POST"])
def add_books_to_loan(id):
for field in request.form:
add_id=int(re.findall( '\d+', field )[0])
try:
db.engine.execute("insert into book_loan_link (book_id, loan_id) values ( {}, {} )".format( add_id, id ))
print("insert into book_loan_link (book_id, loan_id) values ( {}, {} )".format( add_id, id ))
db.session.commit()
except SQLAlchemyError as e:
st.SetAlert("danger")
st.SetMessage("Failed to add books to loan! -- {}".format( e.orig ))
print ("NOT SURE WHAT TO DO if we dont want output" )
return redirect("/loan/{}".format(id))
@app.route("/", methods=["GET"])