Here is an example that uses the current VL
Code:
python:
def ids_for_field(db, ids_of_books, field_name):
# First get all the names for the desired books.
# Use a set to make them unique
unique_names = set()
for tup in db.all_field_for(field_name, ids_of_books).values():
for val in tup:
unique_names.add(val)
# Now get the ids for the names and build the pairs
id_field_pairs = list()
for name in unique_names:
id_field_pairs.append((db.get_item_id(field_name, name), name))
return id_field_pairs
def evaluate(book, context):
print('--------------------')
# Get the list of books in the current VL
ids_in_vl = context.db.data.search_getting_ids('', '', use_virtual_library=True)
# Get the id,val pairs for the desired field
field_pairs = ids_for_field(context.db.new_api, ids_in_vl, 'authors')
print(field_pairs)
return ''