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( "child book details:" )
print( book.child_ref ) 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"]) @app.route("/authors", methods=["GET"])
def authors(): def authors():
@@ -167,20 +167,26 @@ def authors():
def author(id): def author(id):
### DDP: should this be request.form or request.values? ### DDP: should this be request.form or request.values?
author_form = AuthorForm(request.form) author_form = AuthorForm(request.form)
print("we are here")
if request.method == 'POST' and author_form.validate(): if request.method == 'POST' and author_form.validate():
print("we are posting")
id = request.form['id'] id = request.form['id']
author = Author.query.get(id) author = Author.query.get(id)
author.firstnames = request.form['firstnames'] try:
author.surname = request.form['surname'] request.form['submit']
db.session.commit() except:
message="Successfully Updated Author (id={})".format(id) 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: else:
author = Author.query.get(id) author = Author.query.get(id)
author_form = AuthorForm(request.values, obj=author) author_form = AuthorForm(request.values, obj=author)
message="" 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"]) @app.route("/", methods=["GET"])
def main_page(): def main_page():