Quote:
Originally Posted by kjdavies
How about
Code:
program:
'.'.join(filter(None, ($#titlecount,$#pagecount,$series,$#pubseries,$#pubseries_index)))
? I think this should make a string concatenating only the non-None values in the list, and prevent leading or trailing '.'.
|
Problem: that intermixes python and the GPR template language. The template should be rewritten as
Code:
python:
def evaluate(book, context):
vals = (filter(
None,
(
book.get('#myint2'),
book.get('#pagecount'),
book.get('series'),
book.get('#series'),
book.get('#series_index')))
)
vals = ((str(v) if isinstance(v, (int, float)) else v) for v in vals)
return '.'.join(vals)
Note: the list_join() template function ignores empty values, not adding them to the result list. None won't be encountered unless you use raw_field() or $$#.