|
|
@ -45,6 +45,7 @@ def allowed_file(filename):
|
|
|
|
def home():
|
|
|
|
def home():
|
|
|
|
chat_form = ChatForm()
|
|
|
|
chat_form = ChatForm()
|
|
|
|
chat_messages = db.session.query(Chat).all()
|
|
|
|
chat_messages = db.session.query(Chat).all()
|
|
|
|
|
|
|
|
username = 'librarian'
|
|
|
|
|
|
|
|
|
|
|
|
# if request.method == 'POST':
|
|
|
|
# if request.method == 'POST':
|
|
|
|
# if chat_form.validate_on_submit():
|
|
|
|
# if chat_form.validate_on_submit():
|
|
|
@ -53,7 +54,7 @@ def home():
|
|
|
|
# db.session.add(msg)
|
|
|
|
# db.session.add(msg)
|
|
|
|
# db.session.commit()
|
|
|
|
# db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username="librarian")
|
|
|
|
return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username=username)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/hello/<name>')
|
|
|
|
@app.route('/hello/<name>')
|
|
|
|
def hello(name):
|
|
|
|
def hello(name):
|
|
|
@ -348,45 +349,72 @@ def remove_from_stack(bookid, stackid):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## search
|
|
|
|
## search
|
|
|
|
|
|
|
|
view = ['1']
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
def show_books():
|
|
|
|
def show_books():
|
|
|
|
books = db.session.query(Book).all()
|
|
|
|
books = db.session.query(Book).order_by(Book.title)
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
|
|
|
|
view.append('1')
|
|
|
|
|
|
|
|
viewby = '1'
|
|
|
|
|
|
|
|
|
|
|
|
if search.grid.data:
|
|
|
|
if search.grid.data:
|
|
|
|
|
|
|
|
viewby = '2'
|
|
|
|
|
|
|
|
view.append('2')
|
|
|
|
return render_template ('show_books_grid.html', books=books, form=search)
|
|
|
|
return render_template ('show_books_grid.html', books=books, form=search)
|
|
|
|
|
|
|
|
|
|
|
|
if search.listview.data:
|
|
|
|
if search.listview.data:
|
|
|
|
|
|
|
|
viewby = '1'
|
|
|
|
|
|
|
|
view.append('1')
|
|
|
|
return render_template ('show_books.html', books=books, form=search)
|
|
|
|
return render_template ('show_books.html', books=books, form=search)
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
|
|
|
|
newmsg = 'searched for: ' + search.search.data
|
|
|
|
|
|
|
|
# message = search.search.data
|
|
|
|
|
|
|
|
# newmessage = Chat(message)
|
|
|
|
|
|
|
|
# db.session.add(newmessage)
|
|
|
|
|
|
|
|
# db.session.commit()
|
|
|
|
|
|
|
|
# Send search to socket chat
|
|
|
|
|
|
|
|
socketio.emit('channel-' + str(1), {
|
|
|
|
|
|
|
|
'username': 'Search form',
|
|
|
|
|
|
|
|
'text': search.search.data,
|
|
|
|
|
|
|
|
'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True)
|
|
|
|
|
|
|
|
# Save message
|
|
|
|
|
|
|
|
my_new_chat = Chat(message=newmsg)
|
|
|
|
|
|
|
|
db.session.add(my_new_chat)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
db.session.rollback()
|
|
|
|
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby)))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('show_books.html', books=books, form=search)
|
|
|
|
return render_template('show_books.html', books=books, form=search)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/search/<searchtype>/<query>/', methods=['POST', 'GET'])
|
|
|
|
@app.route('/search/<searchtype>/<viewby>/<query>', methods=['POST', 'GET'])
|
|
|
|
def search_results(searchtype, query):
|
|
|
|
def search_results(searchtype, query, viewby):
|
|
|
|
search = SearchForm(request.form, search=query)
|
|
|
|
search = SearchForm(request.form, search=query)
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(14)
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(14)
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).order_by(Book.title)
|
|
|
|
|
|
|
|
viewby = view[-1]
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Title':
|
|
|
|
if searchtype == 'Title':
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).order_by(Book.title)
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Category':
|
|
|
|
if searchtype == 'Category':
|
|
|
|
results=Book.query.filter(Book.category.contains(query))
|
|
|
|
results=Book.query.filter(Book.category.contains(query)).order_by(Book.title)
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Author':
|
|
|
|
if searchtype== 'Author':
|
|
|
|
results=db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query))
|
|
|
|
results=db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query)).order_by(Book.title)
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Stack':
|
|
|
|
if searchtype== 'Stack':
|
|
|
|
results=db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query))
|
|
|
|
results=db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query)).order_by(Book.title)
|
|
|
|
|
|
|
|
|
|
|
|
if searchtype== 'All':
|
|
|
|
if searchtype== 'All':
|
|
|
|
# results=Book.query.whoosh_search(query)
|
|
|
|
# results=Book.query.whoosh_search(query)
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
results=results.union(Book.query.filter(Book.category.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.authors).filter(Author.author_name.contains(query)))
|
|
|
|
results=results.union(db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query)))
|
|
|
|
results=results.union(db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query))).order_by(Book.title)
|
|
|
|
|
|
|
|
|
|
|
|
if results.count() == 0:
|
|
|
|
if results.count() == 0:
|
|
|
|
upload_form = UploadForm(title= query, author='')
|
|
|
|
upload_form = UploadForm(title= query, author='')
|
|
|
@ -397,40 +425,63 @@ def search_results(searchtype, query):
|
|
|
|
percentage = float(count / whole * 100)
|
|
|
|
percentage = float(count / whole * 100)
|
|
|
|
|
|
|
|
|
|
|
|
if search.listview.data:
|
|
|
|
if search.listview.data:
|
|
|
|
|
|
|
|
view.append('1')
|
|
|
|
return render_template('results.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
|
|
|
|
return render_template('results.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
|
|
|
|
|
|
|
|
|
|
|
|
if search.grid.data:
|
|
|
|
if search.grid.data:
|
|
|
|
|
|
|
|
view.append('2')
|
|
|
|
return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
|
|
|
|
return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
newmsg = 'searched for: ' + search.search.data
|
|
|
|
|
|
|
|
socketio.emit('channel-' + str(1), {
|
|
|
|
|
|
|
|
'username': 'Search form',
|
|
|
|
|
|
|
|
'text': search.search.data,
|
|
|
|
|
|
|
|
'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True)
|
|
|
|
|
|
|
|
# Save message
|
|
|
|
|
|
|
|
my_new_chat = Chat(message=newmsg)
|
|
|
|
|
|
|
|
db.session.add(my_new_chat)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
db.session.rollback()
|
|
|
|
|
|
|
|
|
|
|
|
query = search.search.data
|
|
|
|
query = search.search.data
|
|
|
|
results = []
|
|
|
|
results = []
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
|
|
|
|
if viewby == '1':
|
|
|
|
|
|
|
|
print (view[-1])
|
|
|
|
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby)))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby)))
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
if viewby == '2':
|
|
|
|
|
|
|
|
return render_template('results_grid.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
autocomplete_suggestions = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
# ## Search - autocomplete
|
|
|
|
def test1():
|
|
|
|
# autocomplete_suggestions = []
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
autocomplete.load()
|
|
|
|
# @app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
query = request.form['search']
|
|
|
|
# def test1():
|
|
|
|
query_tokenized = query.lower().split()
|
|
|
|
# if request.method == 'POST':
|
|
|
|
print(query_tokenized)
|
|
|
|
# autocomplete.load()
|
|
|
|
word_1 = query_tokenized[-2]
|
|
|
|
# query = request.form['search']
|
|
|
|
word_2 = query_tokenized[-1]
|
|
|
|
# query_tokenized = query.lower().split()
|
|
|
|
#print(word_1)
|
|
|
|
# print(query_tokenized)
|
|
|
|
autocomplete_output = autocomplete.predict(word_1 , word_2)
|
|
|
|
# word_1 = query_tokenized[-2]
|
|
|
|
autocomplete_suggestions.clear()
|
|
|
|
# word_2 = query_tokenized[-1]
|
|
|
|
for suggestion, score in autocomplete_output:
|
|
|
|
# #print(word_1)
|
|
|
|
autocomplete_suggestions.append(suggestion)
|
|
|
|
# autocomplete_output = autocomplete.predict(word_1 , word_2)
|
|
|
|
|
|
|
|
# autocomplete_suggestions.clear()
|
|
|
|
print(autocomplete_suggestions)
|
|
|
|
# for suggestion, score in autocomplete_output:
|
|
|
|
|
|
|
|
# autocomplete_suggestions.append(suggestion)
|
|
|
|
return Response(json.dumps(autocomplete_suggestions), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
|
|
# print(autocomplete_suggestions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# return Response(json.dumps(autocomplete_suggestions), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/add_to_stack/<int:id>', methods=['GET', 'POST'])
|
|
|
|
@app.route('/add_to_stack/<int:id>', methods=['GET', 'POST'])
|
|
|
|
def add_to_stack(id):
|
|
|
|
def add_to_stack(id):
|
|
|
@ -542,7 +593,6 @@ def new_message(message):
|
|
|
|
db.session.rollback()
|
|
|
|
db.session.rollback()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
socketio.run(app)
|
|
|
|
socketio.run(app)
|
|
|
|
#app.run(debug=True,host="0.0.0.0",port="8080")
|
|
|
|
#app.run(debug=True,host="0.0.0.0",port="8080")
|
|
|
|