|
|
@ -335,7 +335,6 @@ def edit_stack_by_id(id):
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('show_stack_by_id', id=id))
|
|
|
|
return redirect(url_for('show_stack_by_id', id=id))
|
|
|
|
return render_template('edit_stack_detail.html', stack=stack, form=form)
|
|
|
|
return render_template('edit_stack_detail.html', stack=stack, form=form)
|
|
|
|
## search
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## search
|
|
|
|
## search
|
|
|
|
|
|
|
|
|
|
|
@ -352,18 +351,28 @@ def show_books():
|
|
|
|
def search_results(searchtype, query):
|
|
|
|
def search_results(searchtype, query):
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Title':
|
|
|
|
if searchtype == 'Title':
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Category':
|
|
|
|
if searchtype == 'Category':
|
|
|
|
results=Book.query.filter(Book.category.contains(query)).all()
|
|
|
|
results=Book.query.filter(Book.category.contains(query))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Author':
|
|
|
|
|
|
|
|
results=db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Stack':
|
|
|
|
|
|
|
|
results=db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query))
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'All':
|
|
|
|
if searchtype== 'All':
|
|
|
|
results=Book.query.whoosh_search(query).all()
|
|
|
|
# results=Book.query.whoosh_search(query)
|
|
|
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
|
|
|
|
results=results.union(Book.query.filter(Book.category.contains(query)))
|
|
|
|
|
|
|
|
results=results.union(db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query)))
|
|
|
|
|
|
|
|
results=results.union(db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query)))
|
|
|
|
|
|
|
|
|
|
|
|
if not results:
|
|
|
|
if results.count() == 0:
|
|
|
|
upload_form = UploadForm(title= query, author='')
|
|
|
|
upload_form = UploadForm(title= query, author='')
|
|
|
|
return render_template('red_link.html', form=upload_form, title=query)
|
|
|
|
return render_template('red_link.html', form=upload_form, title=query)
|
|
|
|
|
|
|
|
|
|
|
@ -372,7 +381,11 @@ def search_results(searchtype, query):
|
|
|
|
results = []
|
|
|
|
results = []
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query)
|
|
|
|
count = results.count()
|
|
|
|
|
|
|
|
whole = Book.query.count()
|
|
|
|
|
|
|
|
percentage = float(count / whole * 100)
|
|
|
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Search - autocomplete
|
|
|
|
## Search - autocomplete
|
|
|
|
autocomplete_suggestions = []
|
|
|
|
autocomplete_suggestions = []
|
|
|
|