|
|
@ -134,16 +134,13 @@ def edit_book_by_id(id): |
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
if user_form.validate_on_submit(): |
|
|
|
# check if the post request has the file part |
|
|
|
title = user_form.title.data # You could also have used request.form['name'] |
|
|
|
input_authors = user_form.author.data # You could also have used request.form['email'] |
|
|
|
# on submit, check fields |
|
|
|
title = user_form.title.data |
|
|
|
input_authors = user_form.author.data |
|
|
|
category = user_form.category.data |
|
|
|
year_published = user_form.year_published.data |
|
|
|
if year_published=="": |
|
|
|
year_published = None |
|
|
|
# save user to database |
|
|
|
#book = Book(title, author, filename, cover, file_extension) |
|
|
|
|
|
|
|
book = Book.query.filter_by(id=id).first() |
|
|
|
book.title = title |
|
|
|
book.category = category |
|
|
@ -159,6 +156,26 @@ def edit_book_by_id(id): |
|
|
|
a = Author(author_name=author_name) |
|
|
|
db.session.add(a) |
|
|
|
book.authors.append(a) |
|
|
|
|
|
|
|
# editing / uploading new file |
|
|
|
if user_form.file.data: |
|
|
|
file = request.files['file'] |
|
|
|
if file.filename == '': |
|
|
|
flash('No selected file') |
|
|
|
return redirect(request.url) |
|
|
|
if file and allowed_file(file.filename): |
|
|
|
filename = secure_filename(file.filename) |
|
|
|
allbooks = db.session.query(Book).all() |
|
|
|
id = book.id |
|
|
|
new_filename = str(id) +"_"+ filename |
|
|
|
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], new_filename) |
|
|
|
name, file_extension = os.path.splitext(new_filename) |
|
|
|
file.save(fullpath) |
|
|
|
book.cover = get_cover(fullpath, name) |
|
|
|
book.file = new_filename |
|
|
|
else: |
|
|
|
flash('allowed file formats: %s' % ALLOWED_EXTENSIONS) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
flash("%s updated" % (title)) |
|
|
|
return redirect(url_for('show_book_by_id', id=id)) |
|
|
|