|
|
@ -85,19 +85,24 @@ def edit_book_by_id(id):
|
|
|
|
if user_form.validate_on_submit():
|
|
|
|
if user_form.validate_on_submit():
|
|
|
|
# check if the post request has the file part
|
|
|
|
# check if the post request has the file part
|
|
|
|
title = user_form.title.data # You could also have used request.form['name']
|
|
|
|
title = user_form.title.data # You could also have used request.form['name']
|
|
|
|
author = user_form.author.data # You could also have used request.form['email']
|
|
|
|
authors = user_form.author.data # You could also have used request.form['email']
|
|
|
|
# save user to database
|
|
|
|
# save user to database
|
|
|
|
#book = Book(title, author, filename, cover, file_extension)
|
|
|
|
#book = Book(title, author, filename, cover, file_extension)
|
|
|
|
book_to_edit.title = title
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
book = Book.query.filter_by(title=title).first()
|
|
|
|
book = Book.query.filter_by(id=id).first()
|
|
|
|
author_table = Author.query.filter_by(book_id=book.id).delete()
|
|
|
|
book.title = title
|
|
|
|
for this_author in author:
|
|
|
|
book.authors= []
|
|
|
|
this_author = Author(this_author.get('author_name'))
|
|
|
|
db.session.commit()
|
|
|
|
book.authors.append(this_author)
|
|
|
|
for author in authors:
|
|
|
|
|
|
|
|
author_name = author.get("author_name")
|
|
|
|
|
|
|
|
if author_name:
|
|
|
|
|
|
|
|
a = db.session.query(Author).filter_by(author_name=author_name).first()
|
|
|
|
|
|
|
|
if a == None:
|
|
|
|
|
|
|
|
a = Author(author_name=author_name)
|
|
|
|
|
|
|
|
db.session.add(a)
|
|
|
|
|
|
|
|
book.authors.append(a)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
flash("%s updated" % (title))
|
|
|
|
flash("%s updated" % (title))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
|
|
|
|
|
|
|
|