|
|
@ -62,7 +62,11 @@ def show_books():
|
|
|
|
books = db.session.query(Book).all()
|
|
|
|
books = db.session.query(Book).all()
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
return redirect((url_for('search_results', query=search.search.data)))
|
|
|
|
if search.select.data == 'Title':
|
|
|
|
|
|
|
|
return redirect((url_for('search_results', query=search.search.data)))
|
|
|
|
|
|
|
|
if search.select.data == 'Category':
|
|
|
|
|
|
|
|
return redirect((url_for('search_cat', query=search.search.data)))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('show_books.html', books=books, form=search)
|
|
|
|
return render_template('show_books.html', books=books, form=search)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/scape', methods=['POST', 'GET'])
|
|
|
|
@app.route('/scape', methods=['POST', 'GET'])
|
|
|
@ -144,6 +148,10 @@ def add_book():
|
|
|
|
upload_form = UploadForm()
|
|
|
|
upload_form = UploadForm()
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
title = upload_form.title.data
|
|
|
|
|
|
|
|
authors = upload_form.author.data
|
|
|
|
|
|
|
|
category = upload_form.category.data
|
|
|
|
|
|
|
|
year_published = upload_form.year_published.data
|
|
|
|
|
|
|
|
|
|
|
|
if upload_form.validate_on_submit():
|
|
|
|
if upload_form.validate_on_submit():
|
|
|
|
if upload_form.upload.data:
|
|
|
|
if upload_form.upload.data:
|
|
|
@ -166,13 +174,6 @@ def add_book():
|
|
|
|
name, file_extension = os.path.splitext(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']
|
|
|
|
|
|
|
|
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, year_published)
|
|
|
|
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:
|
|
|
@ -186,7 +187,6 @@ def add_book():
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
# save user to database
|
|
|
|
# save user to database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash("%s added to the library" % (title))
|
|
|
|
flash("%s added to the library" % (title))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -196,15 +196,7 @@ def add_book():
|
|
|
|
file = open('app/uploads/potential.pdf')
|
|
|
|
file = open('app/uploads/potential.pdf')
|
|
|
|
filename = 'potential.pdf'
|
|
|
|
filename = 'potential.pdf'
|
|
|
|
file_extension = '.pdf'
|
|
|
|
file_extension = '.pdf'
|
|
|
|
cover = get_cover('app/uploads/potential.pdf', 'default')
|
|
|
|
cover = ''
|
|
|
|
|
|
|
|
|
|
|
|
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,year_published)
|
|
|
|
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:
|
|
|
@ -220,7 +212,6 @@ def add_book():
|
|
|
|
flash("%s added to the library" % (title))
|
|
|
|
flash("%s added to the library" % (title))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
return redirect(url_for('show_books'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash_errors(upload_form)
|
|
|
|
flash_errors(upload_form)
|
|
|
|
return render_template('add_book.html', form=upload_form)
|
|
|
|
return render_template('add_book.html', form=upload_form)
|
|
|
|
|
|
|
|
|
|
|
@ -266,10 +257,9 @@ def show_stack_by_id(id):
|
|
|
|
|
|
|
|
|
|
|
|
## search
|
|
|
|
## search
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/search/<query>/', methods=['POST', 'GET'])
|
|
|
|
@app.route('/search/titles/<query>/', methods=['POST', 'GET'])
|
|
|
|
def search_results(query):
|
|
|
|
def search_results(query):
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
books_all=Book.query.all()
|
|
|
|
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(10)
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(10)
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
|
|
|
|
|
|
|
@ -280,11 +270,32 @@ def search_results(query):
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
query = search.search.data
|
|
|
|
query = search.search.data
|
|
|
|
results = []
|
|
|
|
results = []
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
if search.select.data == 'Title':
|
|
|
|
return redirect((url_for('search_results', query=search.search.data)))
|
|
|
|
return redirect((url_for('search_results', query=search.search.data)))
|
|
|
|
|
|
|
|
if search.select.data == 'Category':
|
|
|
|
|
|
|
|
return redirect((url_for('search_cat', query=search.search.data)))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, query=query)
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, query=query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/search/cat/<query>/', methods=['POST', 'GET'])
|
|
|
|
|
|
|
|
def search_cat(query):
|
|
|
|
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(10)
|
|
|
|
|
|
|
|
results=Book.query.filter(Book.category.contains(query)).all()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not results:
|
|
|
|
|
|
|
|
upload_form = UploadForm(category=query)
|
|
|
|
|
|
|
|
return render_template('red_link.html', form=upload_form, category=query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
query = search.search.data
|
|
|
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
if search.select.data == 'Title':
|
|
|
|
|
|
|
|
return redirect((url_for('search_results', query=search.search.data)))
|
|
|
|
|
|
|
|
if search.select.data == 'Category':
|
|
|
|
|
|
|
|
return redirect((url_for('search_cat', query=search.search.data)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, query=query)
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
###
|
|
|
|
# The API
|
|
|
|
# The API
|
|
|
|