View Single Post
Old 10-28-2024, 10:17 AM   #1034
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chaley View Post
Note that it won't work the way you want if a book has more than one author and only one of the authors has a note. The book won't be found by search. I'll look at changing the template.
Quote:
Originally Posted by thiago.eec View Post
Even the second template (item_has_notes)?
Here is a template that checks if all the items for a field have a note.

Code:
python:
def evaluate(book, context):
	field_name = context.arguments[0] if context.arguments is not None and  len(context.arguments) == 1 else None
	if field_name is None:
		raise NameError("The argument for the field name wasn't provided")

	db = context.db.new_api
	items_with_notes = context.globals.get('items_with_notes')
	if items_with_notes is None:
		items_with_notes = db.get_all_items_that_have_notes(field_name)
		context.globals['items_with_notes'] = items_with_notes
		context.globals['item_name_map'] = db.get_item_name_map(field_name)
	item_name_map = context.globals['item_name_map']

	vals = book.get(field_name)
	if vals is None:
		return ''
	if isinstance(vals, str):
		vals = tuple((vals,))
	for val in vals:
		if item_name_map.get(val) not in items_with_notes:
			return ''
	return '1'
It returns '' if any item for a field, for example any author in "authors", doesn't have a note.

I stored it with the name "all_items_have_notes".

I understand that you want to know if any author for a book doesn't have a note. In this case you would use
Code:
not template:"""program: all_items_have_notes('authors')#@#:b:yes"""
chaley is offline   Reply With Quote