Quote:
Originally Posted by chaley
Pontificating aside, one can do what you want with a template-language template but with 5,000 tags it would be excruciatingly slow. This python template doesn't have that problem.
Code:
python:
def evaluate(book, context):
field = 'tags'
# Get the previously computed set of acceptable items, if it exists
all_names_over_count = context.globals.get('all_names_over_count')
if all_names_over_count is None:
db = context.db.new_api
all_names_over_count = set()
counts_by_item = db.get_usage_count_by_id(field)
for item,count in counts_by_item.items():
if count > 5:
all_names_over_count.add(db.get_item_name(field, item))
context.globals['all_names_over_count'] = all_names_over_count
# Check if the current book has any of the acceptable items
item_names_in_book = []
for name in book.get(field):
if name in all_names_over_count:
item_names_in_book.append(name)
return ':@:'.join(item_names_in_book)
|
Code isn't working, throws the error:
Quote:
EXCEPTION: Error in function evaluate on line 8 : AttributeError - 'NoneType' object has no attribute 'new_api'
|