first commit for removing books from a loan itself, works and the scaffold is there for adding new books, code to be written
This commit is contained in:
29
main.py
29
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/<id>", methods=["GET"])
|
||||
@app.route("/books_for_loan/<id>", 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/<id>", 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/<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:
|
||||
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():
|
||||
|
||||
Reference in New Issue
Block a user