mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-10 20:10:00 +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":
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
if custom_query == "":
|
||||||
db.cc_classes[c.id].value == (custom_query == "True")))
|
q = q.filter(~getattr(db.Books, 'custom_column_' + str(c.id)).
|
||||||
elif c.datatype == 'int' or c.datatype == 'float':
|
any(db.cc_classes[c.id].value >= 0))
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
else:
|
||||||
db.cc_classes[c.id].value == custom_query))
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
||||||
elif c.datatype == 'rating':
|
db.cc_classes[c.id].value == bool(custom_query == "True")))
|
||||||
|
elif custom_query != '' and custom_query is not None:
|
||||||
|
if 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",
|
||||||
@ -275,10 +287,23 @@ 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 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