|
|
|
@ -17,7 +17,7 @@ import os
|
|
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
|
|
|
|
|
|
# import sqlite3
|
|
|
|
|
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
|
|
|
|
|
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'chm', 'mobi'])
|
|
|
|
|
|
|
|
|
|
author_schema = AuthorSchema()
|
|
|
|
|
authors_schema = AuthorSchema(many=True)
|
|
|
|
@ -153,7 +153,7 @@ def edit_book_by_id(id):
|
|
|
|
|
@app.route('/add-book', methods=['POST', 'GET'])
|
|
|
|
|
def add_book():
|
|
|
|
|
upload_form = UploadForm()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
if upload_form.validate_on_submit():
|
|
|
|
@ -170,16 +170,21 @@ def add_book():
|
|
|
|
|
return redirect(request.url)
|
|
|
|
|
if file and allowed_file(file.filename):
|
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
|
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
|
|
|
|
name, file_extension = os.path.splitext(filename)
|
|
|
|
|
allbooks = db.session.query(Book).all()
|
|
|
|
|
id = len(allbooks)+1
|
|
|
|
|
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)
|
|
|
|
|
cover = get_cover(fullpath, name)
|
|
|
|
|
title = upload_form.title.data # You could also have used request.form['name']
|
|
|
|
|
authors = upload_form.author.data # You could also have used
|
|
|
|
|
category = upload_form.category.data
|
|
|
|
|
|
|
|
|
|
year_published = upload_form.year_published.data
|
|
|
|
|
#print(author)
|
|
|
|
|
#print(len(author))
|
|
|
|
|
book = Book(title, filename, cover, file_extension, category)
|
|
|
|
|
book = Book(title, filename, cover, file_extension, category, year_published)
|
|
|
|
|
db.session.add(book)
|
|
|
|
|
for author in authors:
|
|
|
|
|
author_name = author.get("author_name")
|
|
|
|
@ -207,9 +212,11 @@ def add_book():
|
|
|
|
|
title = upload_form.title.data # You could also have used request.form['name']
|
|
|
|
|
authors = upload_form.author.data # You could also have used
|
|
|
|
|
category = upload_form.category.data
|
|
|
|
|
|
|
|
|
|
year_published = upload_form.year_published.data
|
|
|
|
|
#print(author)
|
|
|
|
|
#print(len(author))
|
|
|
|
|
book = Book(title, filename, cover, file_extension, category)
|
|
|
|
|
book = Book(title, filename, cover, file_extension, category,year_published)
|
|
|
|
|
db.session.add(book)
|
|
|
|
|
for author in authors:
|
|
|
|
|
author_name = author.get("author_name")
|
|
|
|
|