1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-28 20:39:59 +00:00

Simplified typeahead

This commit is contained in:
Ozzieisaacs 2019-03-24 16:14:42 +01:00
parent 6940bb9b88
commit 0f1db18eae

View File

@ -365,34 +365,38 @@ def get_comic_book(book_id, book_format, page):
# ################################### Typeahead ##################################################################
@web.route("/get_authors_json", methods=['GET', 'POST'])
def get_typeahead(database, query, replace=('','')):
entries = db.session.query(database).filter(database.name.ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries])
return json_dumps
@web.route("/get_authors_json")
@login_required_if_no_ano
def get_authors_json():
if request.method == "GET":
query = request.args.get('q')
entries = db.session.query(db.Authors).filter(db.Authors.name.ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace('|', ',')) for r in entries])
return json_dumps
return get_typeahead(db.Authors, request.args.get('q'), ('|', ','))
@web.route("/get_publishers_json", methods=['GET', 'POST'])
@web.route("/get_publishers_json")
@login_required_if_no_ano
def get_publishers_json():
if request.method == "GET":
query = request.args.get('q')
entries = db.session.query(db.Publishers).filter(db.Publishers.name.ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace('|', ',')) for r in entries])
return json_dumps
return get_typeahead(db.Publishers, request.args.get('q'), ('|', ','))
@web.route("/get_tags_json", methods=['GET', 'POST'])
@web.route("/get_tags_json")
@login_required_if_no_ano
def get_tags_json():
if request.method == "GET":
query = request.args.get('q')
entries = db.session.query(db.Tags).filter(db.Tags.name.ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name) for r in entries])
return json_dumps
return get_typeahead(db.Tags, request.args.get('q'))
@web.route("/get_series_json")
@login_required_if_no_ano
def get_series_json():
if request.method == "GET":
return get_typeahead(db.Series, request.args.get('q'))
@web.route("/get_languages_json", methods=['GET', 'POST'])
@ -410,17 +414,6 @@ def get_languages_json():
return json_dumps
@web.route("/get_series_json", methods=['GET', 'POST'])
@login_required_if_no_ano
def get_series_json():
if request.method == "GET":
query = request.args.get('q')
entries = db.session.query(db.Series).filter(db.Series.name.ilike("%" + query + "%")).all()
# entries = db.session.execute("select name from series where name like '%" + query + "%'")
json_dumps = json.dumps([dict(name=r.name) for r in entries])
return json_dumps
@web.route("/get_matching_tags", methods=['GET', 'POST'])
@login_required_if_no_ano
def get_matching_tags():