diff --git a/main.py b/main.py index 997fe78..02d5e37 100644 --- a/main.py +++ b/main.py @@ -232,7 +232,11 @@ book_schema = BookSchema() def search(): books = Book.query.filter(Book.title.ilike("%{}%".format(request.form['term']))).all() AddSubs(books) - return render_template("books.html", books=books) + if 'InDBox' in request.form: + InDBox=1 + else: + InDBox=0 + return render_template("books.html", books=books, InDBox=InDBox) @app.route("/books", methods=["GET"]) def books(): @@ -240,10 +244,14 @@ def books(): AddSubs(books) return render_template("books.html", books=books ) -@app.route("/books_for_loan/", methods=["GET"]) +@app.route("/books_for_loan/", methods=["GET", "POST"]) def books_for_loan(id): books = Book.query.join(Book_Loan_Link).filter(Book_Loan_Link.loan_id==id).order_by(Book.id).all() - return render_template("books_for_loan.html", books=books) + if request.method == 'POST': + InDBox=1 + else: + InDBox=0 + return render_template("books_for_loan.html", books=books, loan_id=id, InDBox=InDBox) @app.route("/books_for_series/", methods=["GET", "POST"]) def books_for_series(id): @@ -551,6 +559,21 @@ def stats(): stats.append( GetCount( "Num all Books unrated", "rating in (select id from rating where name in ('N/A', 'Undefined'))" ) ) return render_template("stats.html", stats=stats ) +@app.route("/rem_books_from_loan/", 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: + st.SetAlert("danger") + st.SetMessage("Failed to remove books from loan!") + + print( "now redirect to /loan/{}".format(id) ) + return redirect("/loan/{}".format(id)) @app.route("/", methods=["GET"]) def main_page(): diff --git a/templates/base.html b/templates/base.html index 508e675..0f218fe 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,3 +1,4 @@ +{% if not InDBox %} @@ -14,6 +15,46 @@ + + +