remove .format() and get all updates to have crrect content
This commit is contained in:
14
author.py
14
author.py
@@ -16,7 +16,7 @@ class Author(db.Model):
|
||||
firstnames = db.Column(db.String(50), unique=False, 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 Author into json / useful in jinja2
|
||||
@@ -63,11 +63,11 @@ def new_author():
|
||||
try:
|
||||
db.session.add(author)
|
||||
db.session.commit()
|
||||
st.SetMessage( "Created new Author ({})".format(author) )
|
||||
st.SetMessage( f"Created new Author ({author.surname}, {author.firstnames})" )
|
||||
return redirect( '/authors' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to add Author:</b> {}".format( e.orig) )
|
||||
st.SetMessage( f"<b>Failed to add Author:</b> {e.orig}" )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
################################################################################
|
||||
@@ -83,18 +83,18 @@ def author(id):
|
||||
try:
|
||||
author = Author.query.get(id)
|
||||
if 'delete' in request.form:
|
||||
st.SetMessage("Successfully deleted Author: ({})".format( author ) )
|
||||
st.SetMessage( f"Successfully deleted Author: ({author.surname}, {author.firstnames})" )
|
||||
author = Author.query.filter(Author.id==id).delete()
|
||||
if 'submit' in request.form:
|
||||
st.SetMessage("Successfully Updated Author: (From: {}".format(author) )
|
||||
st.SetMessage( f"Successfully Updated Author: (From: {author.surname}, {author.firstnames}" )
|
||||
author.surname = request.form['surname']
|
||||
author.firstnames = request.form['firstnames']
|
||||
st.AppendMessage(" To: {}".format(author) )
|
||||
st.AppendMessage( f" To: {author.surname}, {author.firstnames})" )
|
||||
db.session.commit()
|
||||
return redirect( '/authors' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to modify Author:</b> {}".format(e.orig) )
|
||||
st.SetMessage( f"<b>Failed to modify Author:</b> {e.orig}" )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
else:
|
||||
author = Author.query.get(id)
|
||||
|
||||
Reference in New Issue
Block a user