View Single Post
Old 04-05-2023, 08:34 AM   #561
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,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Well, unless the field (series_index) isn't available for editing with the SFE.
This stored template sets the series index to whatever the argument is:
Code:
python:
def evaluate(book, context):
	args = context.arguments
	if args is None or len(args) != 1:
		return 'Invalid arguments'
	try:
		sidx = float(args[0])
	except:
		return 'Bad series index'
	db = context.db
	from calibre.gui2.ui import get_gui
	gui = get_gui()

	bids = gui.current_view().get_selected_ids()
	results = []
	for bid in bids:
		db.set_series_index(bid, sidx)
		results.append(db.title(bid, index_is_id=True))
	db.refresh_ids(bids)
	gui.current_view().model().refresh_ids(bids)
	return 'Done: ' + ', '.join(results)
You call it by selecting books and running this template in the template tester:
Code:
program: change_series_index(0)
where the 0 is whatever you want.

You can also use it in an Action Chains formula action.

You can't use it in bulk edit search & replace.
chaley is offline   Reply With Quote