|
|
|
@ -969,29 +969,65 @@ def advanced_search():
|
|
|
|
|
q = db.session.query(db.Books)
|
|
|
|
|
include_tag_inputs = request.args.getlist('include_tag')
|
|
|
|
|
exclude_tag_inputs = request.args.getlist('exclude_tag')
|
|
|
|
|
include_series_inputs = request.args.getlist('include_serie')
|
|
|
|
|
exclude_series_inputs = request.args.getlist('exclude_serie')
|
|
|
|
|
include_languages_inputs = request.args.getlist('include_language')
|
|
|
|
|
exclude_languages_inputs = request.args.getlist('exclude_language')
|
|
|
|
|
|
|
|
|
|
author_name = request.args.get("author_name")
|
|
|
|
|
book_title = request.args.get("book_title")
|
|
|
|
|
if author_name: author_name = author_name.strip()
|
|
|
|
|
if book_title: book_title = book_title.strip()
|
|
|
|
|
if include_tag_inputs or exclude_tag_inputs or author_name or book_title:
|
|
|
|
|
if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \
|
|
|
|
|
include_languages_inputs or exclude_languages_inputs or author_name or book_title:
|
|
|
|
|
searchterm = []
|
|
|
|
|
searchterm.extend((author_name, book_title))
|
|
|
|
|
tag_names = db.session.query(db.Tags).filter(db.Tags.id.in_(include_tag_inputs)).all()
|
|
|
|
|
searchterm.extend(tag.name for tag in tag_names)
|
|
|
|
|
# searchterm = " + ".join(filter(None, searchterm))
|
|
|
|
|
serie_names = db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
|
|
|
|
searchterm.extend(serie.name for serie in serie_names)
|
|
|
|
|
language_names = db.session.query(db.Languages).filter(db.Languages.id.in_(include_languages_inputs)).all()
|
|
|
|
|
for lang in language_names:
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
searchterm.extend(language.name for language in language_names)
|
|
|
|
|
searchterm = " + ".join(filter(None, searchterm))
|
|
|
|
|
q = q.filter(db.Books.authors.any(db.Authors.name.like("%" + author_name + "%")),
|
|
|
|
|
db.Books.title.like("%" + book_title + "%"))
|
|
|
|
|
# random = db.session.query(db.Books).order_by(func.random()).limit(config.RANDOM_BOOKS)
|
|
|
|
|
for tag in include_tag_inputs:
|
|
|
|
|
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
|
|
|
|
|
for tag in exclude_tag_inputs:
|
|
|
|
|
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))
|
|
|
|
|
for serie in include_series_inputs:
|
|
|
|
|
q = q.filter(db.Books.series.any(db.Series.id == serie))
|
|
|
|
|
for serie in exclude_series_inputs:
|
|
|
|
|
q = q.filter(not_(db.Books.series.any(db.Series.id == serie)))
|
|
|
|
|
if current_user.filter_language() != "all":
|
|
|
|
|
q = q.filter(db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()))
|
|
|
|
|
else:
|
|
|
|
|
for language in include_languages_inputs:
|
|
|
|
|
q = q.filter(db.Books.languages.any(db.Languages.id == language))
|
|
|
|
|
for language in exclude_languages_inputs:
|
|
|
|
|
q = q.filter(not_(db.Books.series.any(db.Languages.id == language)))
|
|
|
|
|
q = q.all()
|
|
|
|
|
return render_template('search.html', searchterm=searchterm, entries=q)
|
|
|
|
|
tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
|
|
|
|
|
return render_template('search_form.html', tags=tags)
|
|
|
|
|
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
|
|
|
|
if current_user.filter_language() == u"all":
|
|
|
|
|
languages = db.session.query(db.Languages).all()
|
|
|
|
|
for lang in languages:
|
|
|
|
|
try:
|
|
|
|
|
cur_l = LC.parse(lang.lang_code)
|
|
|
|
|
lang.name = cur_l.get_language_name(get_locale())
|
|
|
|
|
except:
|
|
|
|
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
|
|
|
else:
|
|
|
|
|
languages=None
|
|
|
|
|
return render_template('search_form.html', tags=tags, languages=languages, series=series)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/cover/<path:cover_path>")
|
|
|
|
|