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 10-23-2024, 11:41 AM   #151
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,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
so for a custom column, it's just #whatever?
Yes, but in quotes. It is an expression returning a lookup name. You could even use
Code:
('t' &'ags')
if for some reason you wanted to do that.
chaley is offline   Reply With Quote
Old 10-23-2024, 12:48 PM   #152
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,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
EDIT: I pulled the latest changes but I am not seeing inlist_field.
It is an operator, not a function. There isn't anywhere for you to "see" it other than by using it.

Another example:
Code:
program:
	if '^science' inlist_field '#genre' then 'yes' else 'no' fi
NB: I forgot to add the new operator to the syntax highlighting in the template tester so it doesn't yet show as blue. I submitted the required change.
chaley is offline   Reply With Quote
Old 10-23-2024, 12:58 PM   #153
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,563
Karma: 64960981
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Ah, I was looking in the function reference. It works when I tried it.
ownedbycats is offline   Reply With Quote
Old 10-23-2024, 01:08 PM   #154
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,563
Karma: 64960981
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Does inlist_field only work for strings? e.g.:

Code:
program:

	readgoal = strcat('readinggoal:', format_date(today(), 'yyyy'));

	if
		readgoal inlist_field '#admintags'
ownedbycats is offline   Reply With Quote
Old 10-23-2024, 01:12 PM   #155
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,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Does inlist_field only work for strings? e.g.:

Code:
program:

	readgoal = strcat('readinggoal:', format_date(today(), 'yyyy'));

	if
		readgoal inlist_field '#admintags'
Yes, because there isn't a calibre multiple-value field that doesn't contain strings. Note that in your example, the string generated by strcat() must exactly match some item in #admintags', including blanks. That said, if it works with inlist then it will work with inlist_field.

EDIT 2: the changes to the syntax highlighter are now in calibre source.

Last edited by chaley; 10-23-2024 at 06:46 PM. Reason: Removed edit 1 -- identifiers now works in the same way as inlist
chaley is offline   Reply With Quote
Old 10-28-2024, 12:02 PM   #156
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,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
28 Oct 2024 (in calibre source)
  • Improvement to template function has_notes. It now has two variants.
    1. has_note(field_name, field_value) -- if field_value is not '' (the empty string) , return '1' if the value field_value in the field field_name has an attached note, otherwise ''. Example:
      Code:
      has_note('tags', 'Fiction')
      returns '1' if the tag "fiction" has a note, otherwise ''.
    2. (NEW) has_note(field_name, '') -- if the second parameter is '' then return a list of values in field_name that have a note. If no item in the field has a note, return ''. Example:
      Code:
      has_note('authors', '')
      returns a list of authors that have notes, or '' if no author has a note.
    For example, the second variant is useful for showing column icons if any value in the field has a note rather than a specific value.

    You can also test if all the values have a note by comparing the list length of this function's return value against the list length of the values in field_name. Example:
    Code:
    list_count(has_note('authors', ''), '&') ==# list_count_field('authors')
chaley is offline   Reply With Quote
Old 10-28-2024, 02:06 PM   #157
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,088
Karma: 1221485
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Nice. Even simpler. Now I can find all authors without a note like this:

Code:
not template:"""program:
	if $authors in has_note('authors', '') then
		'1'
	else
		 ''
	fi;#@#:t:1"""
thiago.eec is offline   Reply With Quote
Old 10-28-2024, 04:11 PM   #158
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,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by thiago.eec View Post
Nice. Even simpler. Now I can find all authors without a note like this:

Code:
not template:"""program:
	if $authors in has_note('authors', '') then
		'1'
	else
		 ''
	fi;#@#:t:1"""
That search finds books where all authors don't have notes, not any author that doesn't have a note. It compares two lists as strings, not as lists, so the "in" is true if the has_note() result string equals the authors string, which means all authors have notes.

It will also be at least 10 times slower than the template I posted in the other thread. Perhaps as much as 50 times slower. Of course, this only matters if you have lots of books.

This template uses the new has_note() to find books where 1 or more authors don't have a note. It works by returning '1' if all authors for a book have notes, otherwise ''. It will be slightly faster than your template, but nowhere near as fast as the python template.
Code:
program:
	if list_count(has_note('authors', ''), '&') ==# list_count_field('authors') then
		return '1'
	fi;
	''
You could eliminate the outer "not" in the search by making changing the return '1' to return '' and changing the last line to '1'.
chaley is offline   Reply With Quote
Old 10-28-2024, 04:24 PM   #159
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,088
Karma: 1221485
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Oh, I see my mistake now. I'll leave the python template, then.

When using my template, I do think the first time was slow, then other times were fast. I guess it's the work of the cache in action.
________________________

EDIT: I decided to check the difference between the two templates (mine and yours, but not the python one). It seems to find the same results, even if only one author has a note. Then, looking again at the code, I notice it does work:

Example: If i have a book with two authors (AuthorA and AuthorB), and only have notes for AuthorA.

$authors = 'AuthorA & AuthorB'
has_note('authors', '') = 'AuthorA'

Now, the comparison if $authors in has_note('authors', '') will return False, as intended.

But I'm definitely staying with the python template.

Last edited by thiago.eec; 10-28-2024 at 05:11 PM.
thiago.eec is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 04:25 AM
Template Language phossler Calibre 8 01-12-2016 05:37 PM
Help needed with template language Mamaijee Devices 12 02-19-2013 02:52 AM
Help with template language Pepin33 Calibre 8 11-11-2012 09:32 AM
Template language question BookJunkieLI Library Management 7 02-02-2012 07:55 PM


All times are GMT -4. The time now is 02:01 AM.


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