Quote:
Originally Posted by chaley
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
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"""