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 11-04-2019, 05:01 AM   #1
mopkin
Junior Member
mopkin began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Nov 2019
Device: none
A little help with template functions in a composite column, please!


I am not a programmer, and I am stuck with the template in a custom column I am trying to create. I was hoping, someone here could help me.

I have 2 custom columns which I use as source of data for the third column. Column_1 is looking for PDFs in book formats, and when PDF is not present, returns N/A. Here's the expression: {formats:contains(PDF, , N/A)}

Column_2 is a regular text column with permitted values, which has only one value: Yes. (Or empty, if it's a No). This is a "manual" column, where I myself select Yes when needed.

Column_3 derives its values from the first two columns, either Yes, or N/A. I used the example of a relevant expression in the Calibre Manual online and came up with this: {#column_2:'ifempty($, field('#column_1'))'}. It works perfectly fine, correctly returning either Yes, or N/A, or empty.

What I am struggling with, is the empty in Column_3. I would like it to say No, so that the column always has a value, either Yes, or No, or N/A. But as I said, I am not a programmer, so I wasn't able to fix the expression for column_3, so it would return a No when Column_2 is empty.

It is always possible to add a No to Column_2, but I would rather avoid it, because Yes is a very rare occurrence, and it would mean I would have to manually add a No to every other book, when there might be a much easier solution. I would really appreciate if someone with the knowledge of Python (I am assuming, the expression above is in Python) could help me out with this.
mopkin is offline   Reply With Quote
Old 11-04-2019, 06:25 AM   #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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
First, the template language isn't python. It is something I made up.

It seems that the empty value is coming from #column_1. If I am right then this template should work.
Code:
{:'first_non_empty(field('#column_2'), field('#column_1'), 'No')'}
It says use #column_2 if it has a value, otherwise use #column_1 if it has a value, otherwise return 'No'.
chaley is offline   Reply With Quote
Advert
Old 11-05-2019, 11:07 PM   #3
mopkin
Junior Member
mopkin began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Nov 2019
Device: none
Thank you so much Charles! It works perfectly!
mopkin is offline   Reply With Quote
Reply

Tags
column settings, columns, functions, python function, templates


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Plugboard, template, and custom composite column recipes chaley Library Management 976 04-22-2024 06:29 PM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
Composite column template question Anna_R Library Management 4 06-03-2015 03:59 AM
Composite Column BetterRed Calibre 12 09-01-2013 04:58 AM
[Custom Column - Composite] Template Help Requested Ealdwulf Library Management 2 06-16-2012 04:58 AM


All times are GMT -4. The time now is 01:45 PM.


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