diff --git a/cps/templates/search.html b/cps/templates/search.html index d11f3ec8..78396d80 100644 --- a/cps/templates/search.html +++ b/cps/templates/search.html @@ -2,7 +2,7 @@ {% block body %}
{% if entries|length < 1 %} -

{{_('No Results Found')}} {{adv_searchterm}}

+

{{_('No Results Found')}}

{{_('Search Term:')}} {{adv_searchterm}}

{% else %}

{{result_count}} {{_('Results for:')}} {{adv_searchterm}}

diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index 1d98b22b..7a75bbf9 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -167,6 +167,25 @@ {% endif %} + {% if c.datatype == 'datetime' %} +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ {% endif %} + {% if c.datatype in ['text', 'series'] and not c.is_multiple %} {% endif %} diff --git a/cps/web.py b/cps/web.py index adf0d51e..12f3058b 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1067,8 +1067,8 @@ def search(): @login_required_if_no_ano def advanced_search(): values = dict(request.form) - params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_shelf','exclude_shelf','include_language', - 'exclude_language', 'include_extension', 'exclude_extension'] + params = ['include_tag', 'exclude_tag', 'include_serie', 'exclude_serie', 'include_shelf', 'exclude_shelf', + 'include_language', 'exclude_language', 'include_extension', 'exclude_extension'] for param in params: values[param] = list(request.form.getlist(param)) flask_session['query'] = json.dumps(values) @@ -1077,20 +1077,30 @@ def advanced_search(): def adv_search_custom_columns(cc, term, q): for c in cc: - custom_query = term.get('custom_column_' + str(c.id)) - if custom_query != '' and custom_query is not None: - if c.datatype == 'bool': + if c.datatype == "datetime": + custom_start = term.get('custom_column_' + str(c.id) + '_start') + 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( - db.cc_classes[c.id].value == (custom_query == "True"))) - elif c.datatype == 'int' or c.datatype == 'float': + db.cc_classes[c.id].value >= custom_start)) + if custom_end: 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 + "%"))) + db.cc_classes[c.id].value <= custom_end)) + else: + custom_query = term.get('custom_column_' + str(c.id)) + if custom_query != '' and custom_query is not None: + if c.datatype == 'bool': + q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( + 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 @@ -1262,10 +1272,20 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): searchterm = [] cc_present = False for c in cc: - if term.get('custom_column_' + str(c.id)): - searchterm.extend([(u"%s: %s" % (c.name, term.get('custom_column_' + str(c.id))))]) + if c.datatype == "datetime": + 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 + 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: searchterm, pub_start, pub_end = extend_search_term(searchterm,