mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-18 22:20:30 +00:00
Fix for #3109 (search for custom int and float values within ranges)
This commit is contained in:
commit
84f432830c
0
cps/__init__.py
Executable file → Normal file
0
cps/__init__.py
Executable file → Normal file
0
cps/admin.py
Executable file → Normal file
0
cps/admin.py
Executable file → Normal file
0
cps/redirect.py
Executable file → Normal file
0
cps/redirect.py
Executable file → Normal file
@ -24,6 +24,7 @@ from flask_babel import format_date
|
|||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from sqlalchemy.sql.expression import func, not_, and_, or_, text, true
|
from sqlalchemy.sql.expression import func, not_, and_, or_, text, true
|
||||||
from sqlalchemy.sql.functions import coalesce
|
from sqlalchemy.sql.functions import coalesce
|
||||||
|
from sqlalchemy import exists
|
||||||
|
|
||||||
from . import logger, db, calibre_db, config, ub
|
from . import logger, db, calibre_db, config, ub
|
||||||
from .usermanagement import login_required_if_no_ano
|
from .usermanagement import login_required_if_no_ano
|
||||||
@ -81,16 +82,27 @@ 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':
|
if c.datatype == 'bool':
|
||||||
|
if custom_query != "Any":
|
||||||
|
if custom_query == "":
|
||||||
|
q = q.filter(~getattr(db.Books, 'custom_column_' + str(c.id)).
|
||||||
|
any(db.cc_classes[c.id].value >= 0))
|
||||||
|
else:
|
||||||
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 == bool(custom_query == "True")))
|
||||||
elif c.datatype == 'int' or c.datatype == 'float':
|
elif custom_query != '' and custom_query is not None:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
if c.datatype == 'rating':
|
||||||
db.cc_classes[c.id].value == custom_query))
|
|
||||||
elif c.datatype == 'rating':
|
|
||||||
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 == int(float(custom_query) * 2)))
|
db.cc_classes[c.id].value == int(float(custom_query) * 2)))
|
||||||
else:
|
else:
|
||||||
@ -129,10 +141,10 @@ def adv_search_read_status(read_status):
|
|||||||
db_filter = coalesce(ub.ReadBook.read_status, 0) != ub.ReadBook.STATUS_FINISHED
|
db_filter = coalesce(ub.ReadBook.read_status, 0) != ub.ReadBook.STATUS_FINISHED
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if read_status == "True":
|
if read_status == "":
|
||||||
db_filter = db.cc_classes[config.config_read_column].value == True
|
db_filter = coalesce(db.cc_classes[config.config_read_column].value, 2) == 2
|
||||||
else:
|
else:
|
||||||
db_filter = coalesce(db.cc_classes[config.config_read_column].value, False) != True
|
db_filter = db.cc_classes[config.config_read_column].value == bool(read_status == "True")
|
||||||
except (KeyError, AttributeError, IndexError):
|
except (KeyError, AttributeError, IndexError):
|
||||||
log.error("Custom Column No.{} does not exist in calibre database".format(config.config_read_column))
|
log.error("Custom Column No.{} does not exist in calibre database".format(config.config_read_column))
|
||||||
flash(_("Custom Column No.%(column)d does not exist in calibre database",
|
flash(_("Custom Column No.%(column)d does not exist in calibre database",
|
||||||
@ -279,6 +291,19 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
|
|||||||
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 c.datatype == "bool":
|
||||||
|
if term.get('custom_column_' + str(c.id)) != "Any":
|
||||||
|
search_term.extend([("{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))])
|
||||||
|
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
|
||||||
|
@ -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' %}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user