Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 03-23-2015, 04:13 PM   #1
myki
Zealot
myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.
 
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
conditionnal custom column

Greetings,

I am trying to build a custom column, which content must be different, depending on the series field, empty or not (for my kobo bookshelves).

Here is an example :
if {series} exists, i want : {author_sort} - {series}
if {series} is empty, i want : {author_sort}

Can you help me, please ?

Thanks in advance
myki is offline   Reply With Quote
Old 03-23-2015, 06:42 PM   #2
myki
Zealot
myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.
 
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
Hi Myki, here is the solution ! (yes i love to talk to myself, even if i'm not always agree with myself ).

Code:
{authors:'switch(count($, '&'), 1, $, list_item($, 0, '&'))'}{series:| - |}
If {series} is empty, the custom field will be feed with the first author only,
If {series} is not empty, the custom field will be feed with the first author, a "-", a space and the name of the serie.

ex : Rowling, JK - Harry Potter


(yes i love myself )
myki is offline   Reply With Quote
Advert
Old 03-23-2015, 06:59 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Code:
{author_sort}{series:| - |}
See: http://manual.calibre-ebook.com/temp...ced-formatting for the gory details and HOWTO.

EDIT: myki -- didn't see your post until I posted. But there really is no need to jump the gun and assume only the first author is wanted.

Also, you might want to consider reducing your own template to:

Code:
{authors:sublist(0,1,&)}{series:| - |}
Or for that matter,
Code:
{authors:list_item(0,&)}{series:| - |}
works fine too.

Last edited by eschwartz; 03-23-2015 at 07:09 PM.
eschwartz is offline   Reply With Quote
Old 03-24-2015, 05:40 PM   #4
myki
Zealot
myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.
 
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
your code is clear and perfect, thank you very much eschwartz
And to extract the firstname of the first author in author_sort, i use this :
Code:
{author_sort:re((.*?)\,(.*?)( &|),\2)}
Do you know a better code, more clear ??
myki is offline   Reply With Quote
Old 03-24-2015, 08:12 PM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Well, it always gets the first (and middle) name of the last author...

Try this:

Code:
{author_sort:re(^(.*?)\, (.*?)( & .*|$),\2)}
Anchoring the start and end of the string can often be a good idea also re() will keep going through the string to find as many matches as it can.
eschwartz is offline   Reply With Quote
Advert
Old 03-25-2015, 02:38 AM   #6
myki
Zealot
myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.
 
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
Thanks for your help, I like it clear and efficient
I have (I hope) a last improvement to do :
I need to make a custom field (#kobocollections), which content is feed by another custom field if not empty (#categorieperso), and a custom value if empty ({authors:sublist(0,1,&)}{series:| - |}).

I succeeded by using :
Code:
program:
	a = field('#categorieperso');
	b = template('{authors:sublist(0,1,&)}{series:| - |}');
	test(field('#categorieperso'), a, b)
But can you explain to me why with this :
Code:
{#categorieperso:'ifempty($, template('{authors:sublist(0,1,&)}{series:| - |}'))'}
I get a template error formatter when my serie own a " ' " ??

Can you help me again, please ??

Last edited by myki; 03-25-2015 at 03:56 AM.
myki is offline   Reply With Quote
Old 03-25-2015, 04:31 AM   #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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by myki View Post
Thanks for your help, I like it clear and efficient
I have (I hope) a last improvement to do :
I need to make a custom field (#kobocollections), which content is feed by another custom field if not empty (#categorieperso), and a custom value if empty ({authors:sublist(0,1,&)}{series:| - |}).

I succeeded by using :
Code:
program:
	a = field('#categorieperso');
	b = template('{authors:sublist(0,1,&)}{series:| - |}');
	test(field('#categorieperso'), a, b)
FWIW: you could use
Code:
program:
	a = field('#categorieperso');
	b = template('{authors:sublist(0,1,&)}{series:| - |}');
	ifempty(a, b)
or
Code:
program:
	ifempty(
		field('#enum2'), 
		template('{authors:sublist(0,1,&)}{series:| - |}'))
Quote:
But can you explain to me why with this :
Code:
{#categorieperso:'ifempty($, template('{authors:sublist(0,1,&)}{series:| - |}'))'}
I get a template error formatter when my serie own a " ' " ??

Can you help me again, please ??
You cannot put { or } characters in a template program mode template. The substitutions indicated by the {} characters happen before the template program fragment is evaluated, confusing the template evaluator. In your case the apostrophe is being interpreted as a string delimiter, creating a syntax error. You must use general program mode when you wish to evaluate sub-templates.
chaley is offline   Reply With Quote
Old 03-25-2015, 05:09 AM   #8
myki
Zealot
myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.myki can self-interpret dreams as they happen.
 
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
I have adopted your first purpose, thanks again
Calibre is wonderful thanks to the author and to its community, thank you again for your help on this post and the others !
myki is offline   Reply With Quote
Old 03-25-2015, 10:32 AM   #9
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
You don't strictly have to use GPM (when evaluating sub-templates), though, you *could* use TPM and substitute "[[" and "]]".
Granted, any such template is sufficiently complex enough to beg for GPM.
eschwartz is offline   Reply With Quote
Old 03-25-2015, 10:49 AM   #10
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by eschwartz View Post
You don't strictly have to use GPM (when evaluating sub-templates), though, you *could* use TPM and substitute "[[" and "]]".
Actually, you can't use [[ and ]] in myki's template. The problem is the "| - |" stuff inside the quotes.

<Technical>
The template parser runs in two passes. The first, mostly controlled by the python 'format' library, extracts and parses { ... } template information. The second, mostly controlled by my code, extracts TPM functions from inside the program string using the GPM parser. The problem that arises is that the first parser sees the ':| - |' after the #series and connects it with the nearest opening brace ({), which when using [[ and ]] is the one in front of #categorieperso. The result is a mess, causing the parser to throw up its hands.

If you leave the { and } around the series ({series:| - |}) then the parser gets it right, attaching the prefix and suffix to the right variable. Unfortunately, because this parser and evaluator run before the program parser, this sub-template is evaluated and replaced with the result. If that result contains a significant character such as a quote, comma, bracket, or bar then the resulting argument for the template function will be bogus.

I have considered removing the [[ and ]] hack because the rules for successful use approach incomprehensible.
</Technical>
chaley is offline   Reply With Quote
Old 03-25-2015, 11:06 AM   #11
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by chaley View Post
Actually, you can't use [[ and ]] in myki's template. The problem is the "| - |" stuff inside the quotes.
I knew that...

Quote:
<Technical>
The template parser runs in two passes. The first, mostly controlled by the python 'format' library, extracts and parses { ... } template information. The second, mostly controlled by my code, extracts TPM functions from inside the program string using the GPM parser. The problem that arises is that the first parser sees the ':| - |' after the #series and connects it with the nearest opening brace ({), which when using [[ and ]] is the one in front of #categorieperso. The result is a mess, causing the parser to throw up its hands.

If you leave the { and } around the series ({series:| - |}) then the parser gets it right, attaching the prefix and suffix to the right variable. Unfortunately, because this parser and evaluator run before the program parser, this sub-template is evaluated and replaced with the result. If that result contains a significant character such as a quote, comma, bracket, or bar then the resulting argument for the template function will be bogus.

I have considered removing the [[ and ]] hack because the rules for successful use approach incomprehensible.
</Technical>
Yeah, if you cannot get it to work consistently, I agree it shouldn't be there. Just say template() and eval() only work in GPM.
eschwartz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
Custom yes/no column built from long text column Philantrop Library Management 7 03-23-2013 07:44 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM
custom date column from two state column Dopedangel Library Management 7 01-03-2012 08:20 AM
Can custom book data be displayed in a custom column? kiwidude Development 9 03-02-2011 05:35 AM


All times are GMT -4. The time now is 07:56 AM.


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