Implemented #1083 (Advanced search for extensions)
This commit is contained in:
parent
86fe970651
commit
2215bf3d7f
|
@ -31,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<label for="include_tag">{{_('Tags')}}</label>
|
<label for="include_tag">{{_('Tags')}}</label>
|
||||||
<div class="form-group" id="test">
|
<div class="form-group" id="tag">
|
||||||
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
<label id="tag_{{tag.id}}" class="btn btn-primary tags_click">
|
<label id="tag_{{tag.id}}" class="btn btn-primary tags_click">
|
||||||
|
@ -92,6 +92,26 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif%}
|
{% endif%}
|
||||||
|
<label for="include_extension">{{_('Extensions')}}</label>
|
||||||
|
<div class="form-group" id="extension">
|
||||||
|
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||||
|
{% for extension in extensions %}
|
||||||
|
<label id="extension_{{extension.format}}" class="btn btn-primary extension_click">
|
||||||
|
<input type="checkbox" autocomplete="off" name="include_extension" id="include_extension" value="{{extension.format}}">{{extension.format}}</input>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label for="exclude_extension">{{_('Exclude Extensions')}}</label>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||||
|
{% for extension in extensions %}
|
||||||
|
<label id="exclude_extension_{{extension.format}}" class="btn btn-danger extension_click">
|
||||||
|
<input type="checkbox" autocomplete="off" name="exclude_extension" id="exclude_extension" value="{{extension.format}}">{{extension.format}}</input>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
<label for="ratinghigh">{{_('Rating bigger than')}}</label>
|
<label for="ratinghigh">{{_('Rating bigger than')}}</label>
|
||||||
|
|
23
cps/web.py
23
cps/web.py
|
@ -431,6 +431,8 @@ def get_matching_tags():
|
||||||
title_input = request.args.get('book_title')
|
title_input = request.args.get('book_title')
|
||||||
include_tag_inputs = request.args.getlist('include_tag')
|
include_tag_inputs = request.args.getlist('include_tag')
|
||||||
exclude_tag_inputs = request.args.getlist('exclude_tag')
|
exclude_tag_inputs = request.args.getlist('exclude_tag')
|
||||||
|
include_extension_inputs = request.args.getlist('include_extension')
|
||||||
|
exclude_extension_inputs = request.args.getlist('exclude_extension')
|
||||||
q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_input + "%")),
|
q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_input + "%")),
|
||||||
func.lower(db.Books.title).ilike("%" + title_input + "%"))
|
func.lower(db.Books.title).ilike("%" + title_input + "%"))
|
||||||
if len(include_tag_inputs) > 0:
|
if len(include_tag_inputs) > 0:
|
||||||
|
@ -439,6 +441,12 @@ def get_matching_tags():
|
||||||
if len(exclude_tag_inputs) > 0:
|
if len(exclude_tag_inputs) > 0:
|
||||||
for tag in exclude_tag_inputs:
|
for tag in exclude_tag_inputs:
|
||||||
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))
|
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))
|
||||||
|
'''if len(include_extension_inputs) > 0:
|
||||||
|
for tag in exclude_tag_inputs:
|
||||||
|
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))
|
||||||
|
if len(exclude_extension_inputs) > 0:
|
||||||
|
for tag in exclude_tag_inputs:
|
||||||
|
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))'''
|
||||||
for book in q:
|
for book in q:
|
||||||
for tag in book.tags:
|
for tag in book.tags:
|
||||||
if tag.id not in tag_dict['tags']:
|
if tag.id not in tag_dict['tags']:
|
||||||
|
@ -818,6 +826,8 @@ def advanced_search():
|
||||||
exclude_series_inputs = request.args.getlist('exclude_serie')
|
exclude_series_inputs = request.args.getlist('exclude_serie')
|
||||||
include_languages_inputs = request.args.getlist('include_language')
|
include_languages_inputs = request.args.getlist('include_language')
|
||||||
exclude_languages_inputs = request.args.getlist('exclude_language')
|
exclude_languages_inputs = request.args.getlist('exclude_language')
|
||||||
|
include_extension_inputs = request.args.getlist('include_extension')
|
||||||
|
exclude_extension_inputs = request.args.getlist('exclude_extension')
|
||||||
|
|
||||||
author_name = request.args.get("author_name")
|
author_name = request.args.get("author_name")
|
||||||
book_title = request.args.get("book_title")
|
book_title = request.args.get("book_title")
|
||||||
|
@ -843,7 +853,8 @@ def advanced_search():
|
||||||
|
|
||||||
if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \
|
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 or \
|
include_languages_inputs or exclude_languages_inputs or author_name or book_title or \
|
||||||
publisher or pub_start or pub_end or rating_low or rating_high or description or cc_present:
|
publisher or pub_start or pub_end or rating_low or rating_high or description or cc_present or \
|
||||||
|
include_extension_inputs or exclude_extension_inputs:
|
||||||
searchterm = []
|
searchterm = []
|
||||||
searchterm.extend((author_name.replace('|', ','), book_title, publisher))
|
searchterm.extend((author_name.replace('|', ','), book_title, publisher))
|
||||||
if pub_start:
|
if pub_start:
|
||||||
|
@ -872,6 +883,8 @@ def advanced_search():
|
||||||
searchterm.extend([_(u"Rating <= %(rating)s", rating=rating_high)])
|
searchterm.extend([_(u"Rating <= %(rating)s", rating=rating_high)])
|
||||||
if rating_low:
|
if rating_low:
|
||||||
searchterm.extend([_(u"Rating >= %(rating)s", rating=rating_low)])
|
searchterm.extend([_(u"Rating >= %(rating)s", rating=rating_low)])
|
||||||
|
searchterm.extend(ext for ext in include_extension_inputs)
|
||||||
|
searchterm.extend(ext for ext in exclude_extension_inputs)
|
||||||
# handle custom columns
|
# handle custom columns
|
||||||
for c in cc:
|
for c in cc:
|
||||||
if request.args.get('custom_column_' + str(c.id)):
|
if request.args.get('custom_column_' + str(c.id)):
|
||||||
|
@ -896,6 +909,10 @@ def advanced_search():
|
||||||
q = q.filter(db.Books.series.any(db.Series.id == serie))
|
q = q.filter(db.Books.series.any(db.Series.id == serie))
|
||||||
for serie in exclude_series_inputs:
|
for serie in exclude_series_inputs:
|
||||||
q = q.filter(not_(db.Books.series.any(db.Series.id == serie)))
|
q = q.filter(not_(db.Books.series.any(db.Series.id == serie)))
|
||||||
|
for extension in include_extension_inputs:
|
||||||
|
q = q.filter(db.Books.data.any(db.Data.format == extension))
|
||||||
|
for extension in exclude_extension_inputs:
|
||||||
|
q = q.filter(not_(db.Books.data.any(db.Data.format == extension)))
|
||||||
if current_user.filter_language() != "all":
|
if current_user.filter_language() != "all":
|
||||||
q = q.filter(db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()))
|
q = q.filter(db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()))
|
||||||
else:
|
else:
|
||||||
|
@ -936,11 +953,13 @@ def advanced_search():
|
||||||
# tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
|
# tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
|
||||||
tags = db.session.query(db.Tags).filter(tags_filters()).order_by(db.Tags.name).all()
|
tags = db.session.query(db.Tags).filter(tags_filters()).order_by(db.Tags.name).all()
|
||||||
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
||||||
|
extensions = db.session.query(db.Data) \
|
||||||
|
.group_by(db.Data.format).order_by(db.Data.format).all()
|
||||||
if current_user.filter_language() == u"all":
|
if current_user.filter_language() == u"all":
|
||||||
languages = speaking_language()
|
languages = speaking_language()
|
||||||
else:
|
else:
|
||||||
languages = None
|
languages = None
|
||||||
return render_title_template('search_form.html', tags=tags, languages=languages,
|
return render_title_template('search_form.html', tags=tags, languages=languages, extensions=extensions,
|
||||||
series=series, title=_(u"search"), cc=cc, page="advsearch")
|
series=series, title=_(u"search"), cc=cc, page="advsearch")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user