removed debugs, put condition it to detect if saving (supported) or delete (unsupported at present)

This commit is contained in:
2020-11-14 12:08:21 +11:00
parent 3f7fa18253
commit 4b84ba8aa7

22
main.py
View File

@@ -156,7 +156,7 @@ def book(id):
print( "child book details:" )
print( book.child_ref )
return render_template("books.html", books=book_s, subs=sub_book )
return render_template("book.html", books=book_s, subs=sub_book )
@app.route("/authors", methods=["GET"])
def authors():
@@ -167,20 +167,26 @@ def authors():
def author(id):
### DDP: should this be request.form or request.values?
author_form = AuthorForm(request.form)
print("we are here")
if request.method == 'POST' and author_form.validate():
print("we are posting")
id = request.form['id']
author = Author.query.get(id)
author.firstnames = request.form['firstnames']
author.surname = request.form['surname']
db.session.commit()
message="Successfully Updated Author (id={})".format(id)
try:
request.form['submit']
except:
message="Sorry, Deleting unsupported at present"
alert="Danger"
else:
print( "seems to be saving" )
author.firstnames = request.form['firstnames']
author.surname = request.form['surname']
db.session.commit()
message="Successfully Updated Author (id={})".format(id)
alert="Success"
else:
author = Author.query.get(id)
author_form = AuthorForm(request.values, obj=author)
message=""
return render_template("author.html", author=author, message=message, author_form=author_form)
return render_template("author.html", author=author, alert=alert, message=message, author_form=author_form)
@app.route("/", methods=["GET"])
def main_page():