Since this is an old thread that predates the introduction of python templates by chaley, here is the python equivalent for the chaley's GPM template:
Code:
python:
def evaluate(book, context):
vals = context.globals.get('highest_index_ids')
if not vals:
vals = context.globals['highest_index_ids'] = []
db = context.db
cats = db.new_api.get_categories(book_ids=None)
all_series = [ t.name for t in cats['series'] ]
for series in all_series:
book_ids = db.data.search_getting_ids(f'series:"={series}"', '')
indices = {}
for book_id in book_ids:
idx = db.new_api.field_for('series_index', book_id)
indices[idx] = book_id
vals.append(indices[max(indices.keys())])
return '1' if book.id in vals else '0'
This should be a little faster.