|
|
|
@ -78,7 +78,7 @@ def remove_book_by_id(id):
|
|
|
|
|
@app.route('/books/<int:id>/edit', methods=['POST', 'GET'])
|
|
|
|
|
def edit_book_by_id(id):
|
|
|
|
|
book_to_edit = Book.query.filter_by(id=id).first()
|
|
|
|
|
user_form = UserForm_Edit(title = book_to_edit.title, author =book_to_edit.author)
|
|
|
|
|
user_form = UserForm_Edit(title = book_to_edit.title, author =book_to_edit.authors)
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
if user_form.validate_on_submit():
|
|
|
|
@ -91,10 +91,10 @@ def edit_book_by_id(id):
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
book = Book.query.filter_by(title=title).first()
|
|
|
|
|
author_table = Author.query.filter_by(user_id=book.id).delete()
|
|
|
|
|
author_table = Author.query.filter_by(book_id=book.id).delete()
|
|
|
|
|
for this_author in author:
|
|
|
|
|
this_author = Author(this_author.get('author_name'))
|
|
|
|
|
book.author.append(this_author)
|
|
|
|
|
book.authors.append(this_author)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
flash("%s updated" % (title))
|
|
|
|
@ -127,17 +127,20 @@ def add_book():
|
|
|
|
|
file.save(fullpath)
|
|
|
|
|
cover = get_cover(fullpath, name)
|
|
|
|
|
title = user_form.title.data # You could also have used request.form['name']
|
|
|
|
|
author = user_form.author.data # You could also have used
|
|
|
|
|
authors = user_form.author.data # You could also have used
|
|
|
|
|
tag = user_form.tag.data
|
|
|
|
|
print(author)
|
|
|
|
|
print(len(author))
|
|
|
|
|
#print(author)
|
|
|
|
|
#print(len(author))
|
|
|
|
|
book = Book(title, filename, cover, file_extension, tag)
|
|
|
|
|
db.session.add(book)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
book = Book.query.filter_by(title=title).first()
|
|
|
|
|
for this_author in author:
|
|
|
|
|
this_author = Author(this_author.get('author_name'))
|
|
|
|
|
book.author.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()
|
|
|
|
|
# save user to database
|
|
|
|
|
|
|
|
|
@ -159,6 +162,13 @@ def flash_errors(form):
|
|
|
|
|
error
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
@app.route('/authors/<int:id>')
|
|
|
|
|
def show_author_by_id(id):
|
|
|
|
|
author = Author.query.get(id)
|
|
|
|
|
if not author:
|
|
|
|
|
abort(404)
|
|
|
|
|
else:
|
|
|
|
|
return render_template('show_author_detail.html', author=author)
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# The API
|
|
|
|
|