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