|
|
#1 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
|
Variable Series Index Field
Currently I'm using two different templates when I Save Books to Disk. The only difference between the two is that I use {series_index:0>2s||. } if the series has all whole numbers for the index # and {series_index:0>4.1f||. } if the series has partial numbers for the index #.
What I would like is for an automatic way to do this without having to manual adjust the template each time. Examples: If the series goes SomeSeries 1 SomeSeries 2 SomeSeries 3 I want the index to be: 01. 02. 03. However, if the series goes SomeSeries 1 SomeSeries 1.5 SomeSeries 2 SomeSeries 3 I want the index to be: 01.0. 01.5. 02.0 03.0. Is this possible? |
|
|
|
|
|
#2 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,269
Karma: 61916422
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
I use
Code:
series_index:0>5.2s |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
No. To do what you ask, a template would need information about other books being "processed", something that the template system does not support.
You can, of course, do it with a plugin that preprocesses the selection to determine the necessary width of the output field. |
|
|
|
|
|
#4 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
|
That doesn't come anywhere close to what I'm looking for.
Is it possible to set up a regex that only adds the decimal point if it's there without doing a plugin? So SomeSeries 1, SomeSeries 2, SomeSeries 3 would still do exactly the same thing, but: SomeSeries 1 SomeSeries 1.5 SomeSeries 2 SomeSeries 3 would go: 01.
01.5. 02. 03. |
|
|
|
|
|
#5 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Use a general program mode template.
The following template shows one way to do variable formatting. Code:
program:
si = field('series_index');
index_val = test(
field('series'),
contains(si, '\.',
format_number(si, '{0:04.1f}'),
format_number(si, '{0:02d}')),
'');
finish_formatting(index_val, '', '', '.')
An alternate way to do it would be to generate the template string you want depending on the value of series and series_index, then return the result of evaluating that template. Which is easier for you depends on how you think. |
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
|
I apologize for being an idiot - but I can't get that to work. I went into "Template Functions" and put the function name as my_seriesindex and your code as the program code, but I keep getting a compile error.
NameError: name 'field' is not defined The entire template I've been using is: Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>2s||. }{title} - {authors}
Code:
{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>4.1f||. }{title} - {authors}
|
|
|
|
|
|
#7 | ||
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
The following GPM template should do what you want. It is not a particularly elegant solution, but it should be understandable. Code:
program:
t_dot = '{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>4.1f||. }{title} - {authors}';
t_nodot = '{#booktype}/{author_sort:re([.]$,)}/{series}/{series_index:0>2s||. }{title} - {authors}';
t_noseries = t_nodot;
template = test(field('series'),
contains(field('series_index'),
'\.',
t_dot,
t_nodot),
t_noseries);
template(template)
|
||
|
|
|
|
|
#8 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Mar 2013
Device: Nook
|
Thank you SO much. That works perfectly
|
|
|
|
|
|
#9 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
|
Strange compiler errors
Using version 0.9.33.
What am I doing wrong? I always get a compiler error saying Nameerror: "test" is not defined. Usually I know how to code, but here I'm stuck. If I add program: as first line it says: SyntaxError: invalid syntax. It seems the GPM mode is not working? Am I missing something here, some Preferences not correctly set? |
|
|
|
|
|
#10 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
|
Ok, edit: error exists in 32/64-bit version
Last edited by darkul; 06-03-2013 at 07:32 AM. |
|
|
|
|
|
#11 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
|
|
|
|
|
#12 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
|
It's your template, just with t_nodot replaced.
Even used an empty string there. Tried this Code:
program: t_dot = ''; t_nodot = '' Could it be that I have to install calibre from scratch, deleting every single trace it left anywhere on my machine? I try that first before we have to think too much. -> Ok, done that ... same problem as before Last edited by darkul; 06-04-2013 at 03:18 AM. |
|
|
|
|
|
#13 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
That text works fine for me, as shown in the attached screen capture. Where exactly are you putting it when you get the syntax error?
|
|
|
|
|
|
#14 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Sep 2011
Device: none
|
Ah, ok, maybe that's not working at all if I enter it in the wrong windows, though to me this seems illogical. Why is there a posibility to add GPMs in "Template functions" if it is not compiling ok?
Under Preferences - Template functions Though window looks different. Last edited by darkul; 06-04-2013 at 07:19 AM. |
|
|
|
|
|
#15 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You enter GPM templates in any box that can accept a "{ ... }" style template, such as for save-to-disk or send-to-device, or when creating or editing composite custom columns. |
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto Increment Series Index Tweak | penguinaka | Calibre | 16 | 07-30-2011 08:17 PM |
| Series Index Auto Increment | lgladen | Calibre | 4 | 04-14-2011 10:14 AM |
| Variable Search, Replace & Transfer to a new field | flopis | Library Management | 10 | 03-09-2011 12:41 PM |
| Command Line problems: ebook-convert, ebook-meta with tags: --series, --series-index | omnivorous | Calibre | 4 | 11-07-2010 03:42 PM |
| Series index Save to Disk problem | Dopedangel | Calibre | 6 | 08-27-2009 05:54 PM |