![]() |
#1 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
![]()
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'), ','),',')'} Code:
{#shelf: Are there any other mistakes? And keep in mind that I don't even know how I managed to do this much ![]() |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
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)) Code:
{:'myListMerge(field('tags'), field('#shelf'), field('#genre'), field('#length'), field('#character'))'} |
![]() |
![]() |
![]() |
#5 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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,',')'} |
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
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 |