View Single Post
Old 12-11-2024, 12:23 PM   #1040
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,110
Karma: 77213681
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
From chaley is this template which can be used to search for series with more than one book:

Quote:
Originally Posted by chaley View Post
This template search should be fast enough to use in a VL. You probably want to make it a stored template.
Code:
python:
def evaluate(book, context):
	# Return True ('yes') if the value in 'field' is used by more than 'test_count' books.
	# This template only works with single value fields such as Series, Publisher, and enumerations
	field = 'series'
	test_count = 1

	db = context.db.new_api
	id_map = context.globals.get('id_map')
	if id_map is None:
		context.globals['id_map'] = id_map = db.get_item_name_map(field)
		context.globals['item_book_count'] = db.get_usage_count_by_id(field)
	item_book_count = context.globals['item_book_count']

	item_id = id_map.get(book.get(field))
	if item_id is None or item_book_count.get(item_id, 0) <= test_count:
		return ''
	return 'yes'
ownedbycats is offline   Reply With Quote