mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add ability to manipulate int, float, and bool columns in search replace
This commit is contained in:
parent
2662ab485f
commit
84c6bcac39
@ -321,7 +321,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
if (f in ['author_sort'] or
|
if (f in ['author_sort'] or
|
||||||
(fm[f]['datatype'] in ['text', 'series', 'enumeration']
|
(fm[f]['datatype'] in ['text', 'series', 'enumeration']
|
||||||
and fm[f].get('search_terms', None)
|
and fm[f].get('search_terms', None)
|
||||||
and f not in ['formats', 'ondevice', 'sort'])):
|
and f not in ['formats', 'ondevice', 'sort']) or
|
||||||
|
fm[f]['datatype'] in ['int', 'float', 'bool'] ):
|
||||||
self.all_fields.append(f)
|
self.all_fields.append(f)
|
||||||
self.writable_fields.append(f)
|
self.writable_fields.append(f)
|
||||||
if f in ['sort'] or fm[f]['datatype'] == 'composite':
|
if f in ['sort'] or fm[f]['datatype'] == 'composite':
|
||||||
@ -431,6 +432,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
|||||||
val = mi.get('title_sort', None)
|
val = mi.get('title_sort', None)
|
||||||
else:
|
else:
|
||||||
val = mi.get(field, None)
|
val = mi.get(field, None)
|
||||||
|
if isinstance(val, (int, float, bool)):
|
||||||
|
val = str(val)
|
||||||
if val is None:
|
if val is None:
|
||||||
val = [] if fm['is_multiple'] else ['']
|
val = [] if fm['is_multiple'] else ['']
|
||||||
elif not fm['is_multiple']:
|
elif not fm['is_multiple']:
|
||||||
|
@ -134,7 +134,15 @@ class CustomColumns(object):
|
|||||||
|
|
||||||
def adapt_bool(x, d):
|
def adapt_bool(x, d):
|
||||||
if isinstance(x, (str, unicode, bytes)):
|
if isinstance(x, (str, unicode, bytes)):
|
||||||
x = bool(int(x))
|
x = x.lower()
|
||||||
|
if x == 'true':
|
||||||
|
x = True
|
||||||
|
elif x == 'false':
|
||||||
|
x = False
|
||||||
|
elif x == 'none':
|
||||||
|
x = None
|
||||||
|
else:
|
||||||
|
x = bool(int(x))
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def adapt_enum(x, d):
|
def adapt_enum(x, d):
|
||||||
@ -143,9 +151,17 @@ class CustomColumns(object):
|
|||||||
v = None
|
v = None
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
def adapt_number(x, d):
|
||||||
|
if isinstance(x, (str, unicode, bytes)):
|
||||||
|
if x.lower() == 'none':
|
||||||
|
return None
|
||||||
|
if d['datatype'] == 'int':
|
||||||
|
return int(x)
|
||||||
|
return float(x)
|
||||||
|
|
||||||
self.custom_data_adapters = {
|
self.custom_data_adapters = {
|
||||||
'float': lambda x,d : x if x is None else float(x),
|
'float': adapt_number,
|
||||||
'int': lambda x,d : x if x is None else int(x),
|
'int': adapt_number,
|
||||||
'rating':lambda x,d : x if x is None else min(10., max(0., float(x))),
|
'rating':lambda x,d : x if x is None else min(10., max(0., float(x))),
|
||||||
'bool': adapt_bool,
|
'bool': adapt_bool,
|
||||||
'comments': lambda x,d: adapt_text(x, {'is_multiple':False}),
|
'comments': lambda x,d: adapt_text(x, {'is_multiple':False}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user