Custom column datetime now searchable (#1984)
This commit is contained in:
parent
b0cc52e0aa
commit
380292a8aa
|
@ -2,7 +2,7 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="discover">
|
<div class="discover">
|
||||||
{% if entries|length < 1 %}
|
{% if entries|length < 1 %}
|
||||||
<h2>{{_('No Results Found')}} {{adv_searchterm}}</h2>
|
<h2>{{_('No Results Found')}}</h2>
|
||||||
<p>{{_('Search Term:')}} {{adv_searchterm}}</p>
|
<p>{{_('Search Term:')}} {{adv_searchterm}}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h2>{{result_count}} {{_('Results for:')}} {{adv_searchterm}}</h2>
|
<h2>{{result_count}} {{_('Results for:')}} {{adv_searchterm}}</h2>
|
||||||
|
|
|
@ -167,6 +167,25 @@
|
||||||
<input type="number" step="0.01" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value="">
|
<input type="number" step="0.01" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value="">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if c.datatype == 'datetime' %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="{{ 'custom_column_' ~ c.id }}">{{_('From:')}}</label>
|
||||||
|
<div style="position: relative">
|
||||||
|
<input type="date" class="form-control" name="{{ 'custom_column_' ~ c.id }}_start" id="{{ 'custom_column_' ~ c.id }}_start" value="">
|
||||||
|
<input type="text" class="form-control fake-input hidden" id="fake_{{ 'custom_column_' ~ c.id }}_start" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="{{ 'custom_column_' ~ c.id }}">{{_('To:')}}</label>
|
||||||
|
<div style="position: relative">
|
||||||
|
<input type="date" class="form-control" name="{{ 'custom_column_' ~ c.id }}_end" id="{{ 'custom_column_' ~ c.id }}_end" value="">
|
||||||
|
<input type="text" class="form-control fake-input hidden" id="fake_{{ 'custom_column_' ~ c.id }}_end" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if c.datatype in ['text', 'series'] and not c.is_multiple %}
|
{% if c.datatype in ['text', 'series'] and not c.is_multiple %}
|
||||||
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value="">
|
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value="">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
52
cps/web.py
52
cps/web.py
|
@ -1067,8 +1067,8 @@ def search():
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def advanced_search():
|
def advanced_search():
|
||||||
values = dict(request.form)
|
values = dict(request.form)
|
||||||
params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_shelf','exclude_shelf','include_language',
|
params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_shelf', 'exclude_shelf',
|
||||||
'exclude_language', 'include_extension', 'exclude_extension']
|
'include_language', 'exclude_language', 'include_extension', 'exclude_extension']
|
||||||
for param in params:
|
for param in params:
|
||||||
values[param] = list(request.form.getlist(param))
|
values[param] = list(request.form.getlist(param))
|
||||||
flask_session['query'] = json.dumps(values)
|
flask_session['query'] = json.dumps(values)
|
||||||
|
@ -1077,20 +1077,30 @@ def advanced_search():
|
||||||
|
|
||||||
def adv_search_custom_columns(cc, term, q):
|
def adv_search_custom_columns(cc, term, q):
|
||||||
for c in cc:
|
for c in cc:
|
||||||
custom_query = term.get('custom_column_' + str(c.id))
|
if c.datatype == "datetime":
|
||||||
if custom_query != '' and custom_query is not None:
|
custom_start = term.get('custom_column_' + str(c.id) + '_start')
|
||||||
if c.datatype == 'bool':
|
custom_end = term.get('custom_column_' + str(c.id) + '_end')
|
||||||
|
if custom_start:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
db.cc_classes[c.id].value == (custom_query == "True")))
|
db.cc_classes[c.id].value >= custom_start))
|
||||||
elif c.datatype == 'int' or c.datatype == 'float':
|
if custom_end:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
db.cc_classes[c.id].value == custom_query))
|
db.cc_classes[c.id].value <= custom_end))
|
||||||
elif c.datatype == 'rating':
|
else:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
custom_query = term.get('custom_column_' + str(c.id))
|
||||||
db.cc_classes[c.id].value == int(float(custom_query) * 2)))
|
if custom_query != '' and custom_query is not None:
|
||||||
else:
|
if c.datatype == 'bool':
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
|
db.cc_classes[c.id].value == (custom_query == "True")))
|
||||||
|
elif c.datatype == 'int' or c.datatype == 'float':
|
||||||
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
|
db.cc_classes[c.id].value == custom_query))
|
||||||
|
elif c.datatype == 'rating':
|
||||||
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
|
db.cc_classes[c.id].value == int(float(custom_query) * 2)))
|
||||||
|
else:
|
||||||
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
|
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
@ -1262,10 +1272,20 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
||||||
searchterm = []
|
searchterm = []
|
||||||
cc_present = False
|
cc_present = False
|
||||||
for c in cc:
|
for c in cc:
|
||||||
if term.get('custom_column_' + str(c.id)):
|
if c.datatype == "datetime":
|
||||||
searchterm.extend([(u"%s: %s" % (c.name, term.get('custom_column_' + str(c.id))))])
|
column_start = term.get('custom_column_' + str(c.id) + '_start')
|
||||||
|
column_end = term.get('custom_column_' + str(c.id) + '_end')
|
||||||
|
if column_start:
|
||||||
|
searchterm.extend([u"{} >= {}".format(c.name, column_start)])
|
||||||
|
cc_present = True
|
||||||
|
if column_end:
|
||||||
|
searchterm.extend([u"{} <= {}".format(c.name, column_end)])
|
||||||
|
cc_present = True
|
||||||
|
elif term.get('custom_column_' + str(c.id)):
|
||||||
|
searchterm.extend([(u"{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))])
|
||||||
cc_present = True
|
cc_present = True
|
||||||
|
|
||||||
|
|
||||||
if any(tags.values()) or author_name or book_title or publisher or pub_start or pub_end or rating_low \
|
if any(tags.values()) 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 or read_status:
|
or rating_high or description or cc_present or read_status:
|
||||||
searchterm, pub_start, pub_end = extend_search_term(searchterm,
|
searchterm, pub_start, pub_end = extend_search_term(searchterm,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user