mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Two changes:
1) Add the alias "list_contains" to the "in_list" function so that naming is more consistent. 2) Add composite categories to valid grouped searches.
This commit is contained in:
parent
6752ccb57c
commit
fb2f184958
@ -460,8 +460,10 @@ parameters can be statements (sequences of expressions). Note that the definitiv
|
||||
* ``fractional_part(x)`` -- returns the value after the decimal point. For example, ``fractional_part(3.14)`` returns ``0.14``.
|
||||
Throws an exception if ``x`` is not a number.
|
||||
* ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string.
|
||||
* ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well
|
||||
with test or first_non_empty.
|
||||
* ``list_contains(separator, pattern, found_val, ..., not_found_val)`` -- (Alias of ``in_list``) Interpret the field as a list
|
||||
of items separated by `separator`, evaluating the `pattern` against each value in the list. If the `pattern` matches a value,
|
||||
return `found_val`, otherwise return `not_found_val`. The `pattern` and `found_value` can be repeated as many times as desired,
|
||||
permitting returning different values depending on the search. The patterns are checked in order. The first match is returned.
|
||||
* ``list_difference(list1, list2, separator)`` -- return a list made by removing from `list1` any item found in `list2`,
|
||||
using a case-insensitive comparison. The items in `list1` and `list2` are separated by separator, as are the items in the returned list.
|
||||
* ``list_equals(list1, sep1, list2, sep2, yes_val, no_val)`` -- return `yes_val` if `list1` and `list2` contain the same items,
|
||||
@ -482,6 +484,8 @@ parameters can be statements (sequences of expressions). Note that the definitiv
|
||||
* ``mod(x)`` -- returns the remainder of ``x / y``, where ``x``, ``y``, and the result are integers. Throws an exception if either ``x`` or
|
||||
``y`` is not a number.
|
||||
* ``multiply(x, y, ...)`` -- returns the product of its arguments. Throws an exception if any argument is not a number.
|
||||
* ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well
|
||||
with test or first_non_empty.
|
||||
* ``ondevice()`` -- return the string "Yes" if ``ondevice`` is set, otherwise return the empty string
|
||||
* ``or(value, value, ...)`` -- returns the string ``"1"`` if any value is not empty, otherwise returns the empty string. This function works
|
||||
well with test or `first_non_empty`. You can have as many values as you want.
|
||||
|
@ -8,6 +8,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
from PyQt5.Qt import QApplication
|
||||
|
||||
from calibre.db.categories import find_categories
|
||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, \
|
||||
CommaSeparatedList, AbortCommit
|
||||
from calibre.gui2.preferences.search_ui import Ui_Form
|
||||
@ -67,15 +68,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.gst = db.prefs.get('grouped_search_terms', {}).copy()
|
||||
self.orig_gst_keys = list(self.gst.keys())
|
||||
|
||||
fl = []
|
||||
for f in db.all_field_keys():
|
||||
fm = db.metadata_for_field(f)
|
||||
if not fm['search_terms']:
|
||||
continue
|
||||
if not fm['is_category']:
|
||||
continue
|
||||
fl.append(f)
|
||||
self.gst_value.update_items_cache(fl)
|
||||
fm = db.new_api.field_metadata
|
||||
categories = [x[0] for x in find_categories(fm) if fm[x[0]]['search_terms']]
|
||||
self.gst_value.update_items_cache(categories)
|
||||
self.fill_gst_box(select=None)
|
||||
|
||||
self.user_category_layout.setContentsMargins(0, 30, 0, 0)
|
||||
|
@ -629,6 +629,8 @@ class BuiltinInList(BuiltinFormatterFunction):
|
||||
'many times as desired, permitting returning different values '
|
||||
'depending on the search. The patterns are checked in order. The '
|
||||
'first match is returned.')
|
||||
aliases = ['list_contains']
|
||||
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val, sep, *args):
|
||||
if (len(args) % 2) != 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user