remove .format() and get all updates to have crrect content
This commit is contained in:
14
loan.py
14
loan.py
@@ -20,7 +20,7 @@ class Loan(db.Model):
|
||||
date_lent = db.Column(db.Date, nullable=False )
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, firstnames: {}, surname: {}>".format(self.id,self.firstnames, self.surname)
|
||||
return f"<id: {self.id}, firstnames: {self.firstnames}, surname: {self.surname}>"
|
||||
|
||||
################################################################################
|
||||
# Helper class that inherits a .dump() method to turn class Loan into json / useful in jinja2
|
||||
@@ -69,11 +69,11 @@ def new_loan():
|
||||
try:
|
||||
db.session.add(loan)
|
||||
db.session.commit()
|
||||
st.SetMessage( "Created new Loan (id={})".format(loan.id) )
|
||||
st.SetMessage( f"Created new Loan (id={loan.id})" )
|
||||
return redirect( '/loans' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to add Loan:</b> {}".format( e.orig) )
|
||||
st.SetMessage( f"<b>Failed to add Loan:</b> {e.orig}" )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
|
||||
@@ -90,12 +90,12 @@ def loan(id):
|
||||
loan = Loan.query.get(id)
|
||||
try:
|
||||
if 'delete' in request.form:
|
||||
st.SetMessage("Successfully deleted (id={}, who={} {})".format( loan.id, loan.firstnames, loan.surname ) )
|
||||
st.SetMessage( f"Successfully deleted (id={loan.id}, who={loan.firsnames} {loan.surname})" )
|
||||
# fall back to direct sql because loan.py is imported before Book_Loan_Link exists
|
||||
db.engine.execute("delete from book_loan_link where loan_id = {}".format( loan.id ))
|
||||
db.engine.execute( f"delete from book_loan_link where loan_id = {loan.id}" )
|
||||
loan = Loan.query.filter(Loan.id==id).delete()
|
||||
if 'submit' in request.form:
|
||||
st.SetMessage("Successfully Updated Loan (id={})".format(id) )
|
||||
st.SetMessage( f"Successfully Updated Loan (id={id})" )
|
||||
loan.firstnames = request.form['firstnames']
|
||||
loan.surname = request.form['surname']
|
||||
loan.surname = request.form['surname']
|
||||
@@ -105,7 +105,7 @@ def loan(id):
|
||||
return redirect( '/loans' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to modify Loan:</b> {}".format(e.orig) )
|
||||
st.SetMessage( f"<b>Failed to modify Loan:</b> {e.orig}" )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
else:
|
||||
loan = Loan.query.get(id)
|
||||
|
||||
Reference in New Issue
Block a user