1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-19 06:30:29 +00:00

Search custom integer, custom_float in range

Search custom bool like read status (unfinished)
This commit is contained in:
Ozzie Isaacs 2024-07-30 19:20:13 +02:00
parent 8d9f301aea
commit 12d46d33d9
2 changed files with 50 additions and 10 deletions

View File

@ -81,13 +81,24 @@ def adv_search_custom_columns(cc, term, q):
if custom_end: 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(
func.datetime(db.cc_classes[c.id].value) <= func.datetime(custom_end))) func.datetime(db.cc_classes[c.id].value) <= func.datetime(custom_end)))
elif c.datatype in ["int", "float"]:
custom_low = term.get('custom_column_' + str(c.id) + '_low')
custom_high = term.get('custom_column_' + str(c.id) + '_high')
if custom_low:
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
db.cc_classes[c.id].value >= custom_low))
if custom_high:
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
db.cc_classes[c.id].value <= custom_high))
else: else:
custom_query = term.get('custom_column_' + str(c.id)) custom_query = term.get('custom_column_' + str(c.id))
if custom_query != '' and custom_query is not None: if c.datatype == 'bool' and custom_query != "Any":
if c.datatype == 'bool': # ToDo:
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any( q = q.filter(coalesce(db.cc_classes[config.config_read_column].value, False) != True)
db.cc_classes[c.id].value == (custom_query == "True"))) q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
elif c.datatype == 'int' or c.datatype == 'float': db.cc_classes[c.id].value == (custom_query == "True")))
elif custom_query != '' and custom_query is not None:
if c.datatype == 'int' or c.datatype == 'float':
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_query))
elif c.datatype == 'rating': elif c.datatype == 'rating':
@ -275,10 +286,19 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
cc_present = True cc_present = True
if column_end: if column_end:
search_term.extend(["{} <= {}".format(c.name, search_term.extend(["{} <= {}".format(c.name,
format_date(datetime.strptime(column_end, "%Y-%m-%d").date(), format_date(datetime.strptime(column_end, "%Y-%m-%d").date(),
format='medium') format='medium')
)]) )])
cc_present = True cc_present = True
if c.datatype in ["int", "float"]:
column_low = term.get('custom_column_' + str(c.id) + '_low')
column_high = term.get('custom_column_' + str(c.id) + '_high')
if column_low:
search_term.extend(["{} >= {}".format(c.name, column_low)])
cc_present = True
if column_high:
search_term.extend(["{} <= {}".format(c.name,column_high)])
cc_present = True
elif term.get('custom_column_' + str(c.id)): elif term.get('custom_column_' + str(c.id)):
search_term.extend([("{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))]) search_term.extend([("{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))])
cc_present = True cc_present = True

View File

@ -158,21 +158,41 @@
{% if cc|length > 0 %} {% if cc|length > 0 %}
{% for c in cc %} {% for c in cc %}
<div class="form-group"> <div class="form-group">
<!--input type="number" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value=""-->
<label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label> <label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label>
{% if c.datatype == 'bool' %} {% if c.datatype == 'bool' %}
<select name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" class="form-control"> <select name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" class="form-control">
<option value="" selected></option> <option value="Any" selected>{{_('Any')}}</option>
<option value="">{{_('Empty')}}</option>
<option value="True" >{{_('Yes')}}</option> <option value="True" >{{_('Yes')}}</option>
<option value="False" >{{_('No')}}</option> <option value="False" >{{_('No')}}</option>
</select> </select>
{% endif %} {% endif %}
{% if c.datatype == 'int' %} {% if c.datatype == 'int' %}
<input type="number" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value=""> <div class="row">
<div class="form-group col-sm-6">
<label for="{{ 'custom_column_' ~ c.id }}_low">{{_('From:')}}</label>
<input type="number" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}_low" id="{{ 'custom_column_' ~ c.id }}_low" value="">
</div>
<div class="form-group col-sm-6">
<label for="{{ 'custom_column_' ~ c.id }}_high">{{_('To:')}}</label>
<input type="number" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}_high" id="{{ 'custom_column_' ~ c.id }}_high" value="">
</div>
</div>
{% endif %} {% endif %}
{% if c.datatype == 'float' %} {% if c.datatype == 'float' %}
<input type="number" step="0.01" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value=""> <div class="row">
<div class="form-group col-sm-6">
<label for="{{ 'custom_column_' ~ c.id }}_low">{{_('From:')}}</label>
<input type="number" step="0.01" class="form-control" name="{{ 'custom_column_' ~ c.id }}_low" id="{{ 'custom_column_' ~ c.id }}_low" value="">
</div>
<div class="form-group col-sm-6">
<label for="{{ 'custom_column_' ~ c.id }}_high">{{_('To:')}}</label>
<input type="number" step="0.01" class="form-control" name="{{ 'custom_column_' ~ c.id }}_high" id="{{ 'custom_column_' ~ c.id }}_high" value="">
</div>
</div>
<!--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' %} {% if c.datatype == 'datetime' %}