|
|
@ -6,7 +6,7 @@ This file creates your application.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from app import app, db, socketio, DOMAIN
|
|
|
|
from app import app, db, socketio, DOMAIN
|
|
|
|
from flask import Flask, Response, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
|
|
|
|
from flask import Flask, Response, session, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
from sqlalchemy.sql.expression import func, select
|
|
|
|
from sqlalchemy.sql.expression import func, select
|
|
|
|
from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm
|
|
|
|
from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm
|
|
|
@ -303,6 +303,8 @@ def show_stack_by_id(id, is_tab=False):
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
def show_books():
|
|
|
|
def show_books():
|
|
|
|
|
|
|
|
autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
|
|
|
|
|
|
|
|
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':
|
|
|
@ -338,11 +340,11 @@ def search_results(searchtype, query):
|
|
|
|
|
|
|
|
|
|
|
|
## Search - autocomplete
|
|
|
|
## Search - autocomplete
|
|
|
|
autocomplete_suggestions = []
|
|
|
|
autocomplete_suggestions = []
|
|
|
|
|
|
|
|
autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
def test1():
|
|
|
|
def test1():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
autocomplete.load()
|
|
|
|
|
|
|
|
query = request.form['search']
|
|
|
|
query = request.form['search']
|
|
|
|
query_tokenized = query.lower().split()
|
|
|
|
query_tokenized = query.lower().split()
|
|
|
|
print(query_tokenized)
|
|
|
|
print(query_tokenized)
|
|
|
@ -354,9 +356,13 @@ def test1():
|
|
|
|
for suggestion, score in autocomplete_output:
|
|
|
|
for suggestion, score in autocomplete_output:
|
|
|
|
autocomplete_suggestions.append(suggestion)
|
|
|
|
autocomplete_suggestions.append(suggestion)
|
|
|
|
|
|
|
|
|
|
|
|
print(autocomplete_suggestions)
|
|
|
|
session['autocomplete_suggestions'] = str(autocomplete_suggestions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(session['autocomplete_suggestions'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response(json.dumps(session['autocomplete_suggestions']), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
|
|
return Response(json.dumps(autocomplete_suggestions), mimetype='application/json')
|
|
|
|
## STACKS!
|
|
|
|
|
|
|
|
|
|
|
|
@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):
|
|
|
|