View Single Post
Old 05-07-2024, 11:52 PM   #7
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
Your python template smashes all the author names together without separation. Is that what you want? I think you want this:
Code:
python:
def evaluate(book, context):
	if book.series is None:
		author_str = ' & '.join(book.authors)
		book_str = book.title + ' - ' + author_str + '/' + book.title + ' - ' + author_str
	else:
		book_str = book.series + '/' + book.series + ' - ' + f"{int(book.series_index):02}" + ' - ' + book.title
	return book_str
or perhaps this, simplified somewhat using 'f' strings:
Code:
python:
def evaluate(book, context):
	if book.series is None:
		author_str = ' & '.join(book.authors)
		book_str = f'{book.title} - {author_str}/{book.title} - {author_str}'
	else:
		book_str = f'{book.series}/{book.series} - {int(book.series_index):02} - {book.title}'
	return book_str
For completeness, here is the equivalent template in GPM:
Code:
program:
	if $series then
		res = template('{series}/{series} - {series_index:0>2s} - {title}')
	else
		res = template('{title} - {authors}/{title} - {authors}')
	fi;
	res
For both templates: it isn't clear that you will get what you want if the series index is a floating point number such as 2.3. The python template drops the fraction. The GPM template includes it but doesn't respect the length. If you really want to ignore the fraction then the series index part of the GPM template should be
Code:
{series_index:0>2.0f}
chaley is offline   Reply With Quote