Quote:
Originally Posted by chaley
I decided to give it a try because I need more experience with the new calibre db layer.
Here is a standalone python program built on calibre's db layer that does what I think you want. It fills in a custom text column with the proper format for a series, computed by looking at all the books in the series.
|
Thanks, I solved it a few days ago by creating a customized column which holds a formatting template. (e.g. 9.99 will output a 2 as 2.00, 99.99 will output a 2.5 as 02.50, 999 will output 2 as 002)
Right now I populate this column manually, but I will either write a script or a plugin to do that for me. Just not sure when I will find the time to do so.
I have a concept, but I will have to look into plugin development in more detail.
If you are interested, here is my format_index function:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, template):
# Check if the argument is empty. If so, return the empty string
if val == '':
return ''
# Return the input as is, if template is empty
if template == '':
return val
# Not empty. Must be a number. If it isn't, bad things will happen.
# split the strings in integer and fractional parts
v = val.split('.')
t = template.split('.')
if len(v) == 1:
v.extend('0')
# trim leading and trailing zeros
v_int = v[0].lstrip( '0' )
if len(t) != 1:
v_frac = v[1].rstrip( '0' )
# determine the number of digits for the integer and fractional part of the template
digits_int = len(t[0].lstrip('0'))
if len(t) != 1:
digits_frac = len(t[1].rstrip('0'))
# pad the input val according to the template
val_int = v_int.rjust(digits_int, '0')
if len(t) != 1 and digits_frac != 0:
val_frac = v_frac.ljust(digits_frac, '0')
retval = val_int + '.' + val_frac
else:
retval = val_int
return retval
I call it like this:
Code:
program: format_index(field('series_index'), field('#seriestemplate'))