Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 10-14-2011, 08:16 AM   #1
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
Question help with custom column

Basically I am trying to make a list of tags, #shelf (merge these two) and remove all values which are in #genre, #character, #legth.

I have been trying to make it on my own half successfully. I tried list_differences

Code:
{#shelf:'list_difference(list_union(field('tags'), field('#shelf'), ','), list_union(list_union(field('#genre'), field('#length'), ','), field('#character'), ','),',')'}
Apparently the beginning
Code:
{#shelf:
does nothing but if I remove it, it stops working. How do I need to edit it to make it correct? Now it does the job, but I think it's a little incorrect. Might get wrong results or something.

Are there any other mistakes?

And keep in mind that I don't even know how I managed to do this much . That's my most complicated creation for calibre.
Noughty is offline   Reply With Quote
Old 10-14-2011, 12:51 PM   #2
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
As for your first question, you can use "{:" instead of "{#shelf:".

Your template seems to do what you want. However, the performance will be less than ideal. This is a case where you should use a custom template function, which will be at least 100 times faster. However, that would require you to write the function in python using calibre's template function editor (preferences -> template functions), which you might not be prepared to do.
chaley is offline   Reply With Quote
Advert
Old 10-14-2011, 03:31 PM   #3
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
Thanks. After all day dealing with templates I will dream them for sure. I don't even want to think of python.

Thanks for clearing that up. I fixed it up.
Noughty is offline   Reply With Quote
Old 10-15-2011, 03:41 AM   #4
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Just for fun, I wrote the custom template function to do this job.

Code:
Function name: myListMerge (or whatever you want)
Argument count: 5
Program code:
def evaluate(self, formatter, kwargs, mi, locals, tags, shelf, genre, length, character):
	r = set([t.strip() for t in tags.split(',') if t.strip()])
	r |= set([t.strip() for t in shelf.split(',') if t.strip()])
	r -= set([t.strip() for t in genre.split(',') if t.strip()])
	r -= set([t.strip() for t in length.split(',') if t.strip()])
	r -= set([t.strip() for t in character.split(',') if t.strip()])
	return ', '.join(sorted(r))
You would use it like
Code:
{:'myListMerge(field('tags'), field('#shelf'), field('#genre'), field('#length'), field('#character'))'}
In fact, I don't suggest that you use it unless you understand it, otherwise you won't be able to maintain it. I did it because I was curious.
chaley is offline   Reply With Quote
Old 10-15-2011, 05:31 AM   #5
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
Who knows maybe one day I get that too. Now I am starting to actually understand templates and how to use them. Once you get the "grammar" all you need is to find the function which does what you want.

My previous result was messy so I edited it:

Code:
{:'list_sort(list_difference(list_union(field('#shelf'), field('tags'), ','), list_union(list_union(field('#genre'), field('#length'), ','), field('#character'), ','),','),0,',')'}
Returns me a nice alphabetical list of all tags, shelves which aren't categorized into separate lists. And I can easily edit it for new categories etc.
Noughty is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can custom book data be displayed in a custom column? kiwidude Development 9 03-02-2011 05:35 AM
Need help with this custom Column. Rie142 Library Management 2 02-20-2011 09:51 AM
Custom Column Format aceflor Calibre 5 12-10-2010 10:28 AM
custom column i need a little help shinken Calibre 3 09-15-2010 03:41 AM
Custom Column Problem MSJim Calibre 7 09-08-2010 05:07 PM


All times are GMT -4. The time now is 12:56 PM.


MobileRead.com is a privately owned, operated and funded community.