I have a saved template function, transform_awards(). However, the following template code gives an error when trying to set it for the Collections template in the Collections, covers & uploads tab:
Code:
program: transform_awards()
This used to work with the KoboTouchExtended driver, but now when I try to click OK to persist my changes in the KoboTouch configuration, I get:
Quote:
calibre, version 8.7.0
ERROR: Invalid template for Collections template:: <p>The template "program: transform_awards()" is invalid:<br>Interpreter: Internal error evaluating an expression: 'list index out of range' - line number 1
|
However, as you can see from the template tester, it should work fine:
The code for my template function:
Code:
def evaluate(self, formatter, kwargs, metadata, _locals):
awards = metadata.get('#awards')
if not awards:
return ''
transformed_awards = []
for award in awards:
# Split the award record into its components
components = award.split('.')
# Extract the name of the award and the category
award_name = components[0]
award_name = award_name.removesuffix(' Award').removesuffix(' Awards')
category_name = components[1]
category_name = category_name.removeprefix('Best ')
# Extract the year from the record and determine the decade it falls in
year = int(components[2])
decade = str(year // 10 * 10) + "s"
# Extract the rank from the record and determine whether or not it is a winner
rank = components[3]
if rank == "winner":
rank_message = "winners"
else:
rank_message = "nominees, etc."
# Combine the components into the desired format
transformed_awards.append(f"Awards: {award_name}, {category_name} ({rank_message})")
return ':@:'.join(transformed_awards)
This seems like a bug, which is why I am reporting it, but if I am doing something wrong, then I appreciate any help getting me back in operation with my collections template.

Thank you!