Quote:
Originally Posted by chaley
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 $$#.
|
My bad, I should've looked it up. I'd assumed list_join was a Python function.
Looking at the documentation, the semantics of list_join seems odd to me... but I think I see now how it works.