Add ability to manipulate int, float, and bool columns in search replace

This commit is contained in:
Charles Haley 2011-01-05 12:59:18 +00:00
parent 2662ab485f
commit 84c6bcac39
2 changed files with 23 additions and 4 deletions

View File

@ -321,7 +321,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
if (f in ['author_sort'] or
(fm[f]['datatype'] in ['text', 'series', 'enumeration']
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.writable_fields.append(f)
if f in ['sort'] or fm[f]['datatype'] == 'composite':
@ -431,6 +432,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
val = mi.get('title_sort', None)
else:
val = mi.get(field, None)
if isinstance(val, (int, float, bool)):
val = str(val)
if val is None:
val = [] if fm['is_multiple'] else ['']
elif not fm['is_multiple']:

View File

@ -134,6 +134,14 @@ class CustomColumns(object):
def adapt_bool(x, d):
if isinstance(x, (str, unicode, bytes)):
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
@ -143,9 +151,17 @@ class CustomColumns(object):
v = None
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 = {
'float': lambda x,d : x if x is None else float(x),
'int': lambda x,d : x if x is None else int(x),
'float': adapt_number,
'int': adapt_number,
'rating':lambda x,d : x if x is None else min(10., max(0., float(x))),
'bool': adapt_bool,
'comments': lambda x,d: adapt_text(x, {'is_multiple':False}),