View Single Post
Old 02-25-2014, 03:24 AM   #18
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,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Purple Lady View Post
I'm using a template function - I copied something Chaley did for someone for the sub collections for Sony PRS+ to start with and changed it to suit me. I have categories that I want as a top level collection, and genres that I want to combine with the #read column. I used to have series and author collections as well, but CC takes care of those.

Spoiler:
Code:
def evaluate(self, formatter, kwargs, mi, locals, cats, genre):
    categories = set([v.strip() for v in cats.split(',') if v.strip()])
    genres = set([v.strip() for v in genre.split(',') if v.strip()])
    res = []

    tags = [v.strip() for v in kwargs.get('tags') if v.strip()]
    isread = kwargs.get('#read')
	
	for v in tags:
		if v in categories:
			res.append(v)
		elif v in genres:
			if isread:
				res.append('Genre ' + isread+ '|' + v)
			else:
				res.append('Genre|'  + v)
		elif isread:
			res.append(isread + '|' + v)
		else:
			res.append('stuff|'  + v)

    if isread:
		res.append(isread) 
            
    return ', '.join(res)


I end up with these groupings:
Borrowed, Genre unread|Non Fiction, unread
read|-bought, Genre read|Mystery - Thriller, read
unread|-free, Genre unread|Science Fiction, unread
You can use a yes/no column (lets call it #read_yesno) by changing the line
Code:
isread = kwargs.get('#read')
to be
Code:
isread = kwargs.get('#read_yesno')
if isread == 'Yes': isread = 'read'
elif isread == 'No': isread = 'unread'
else: isread = ''
chaley is offline   Reply With Quote