Add the ondevice() function to the template language

This commit is contained in:
Charles Haley 2011-05-29 10:04:34 +01:00
parent 0f0efc1ca1
commit 6c26b9debc
3 changed files with 20 additions and 2 deletions

View File

@ -860,6 +860,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
mi.uuid = row[fm['uuid']] mi.uuid = row[fm['uuid']]
mi.title_sort = row[fm['sort']] mi.title_sort = row[fm['sort']]
mi.book_size = row[fm['size']] mi.book_size = row[fm['size']]
mi.ondevice_col= row[fm['ondevice']]
mi.last_modified = row[fm['last_modified']] mi.last_modified = row[fm['last_modified']]
formats = row[fm['formats']] formats = row[fm['formats']]
if not formats: if not formats:

View File

@ -255,6 +255,7 @@ The following functions are available in addition to those described in single-f
* ``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. You can have as many values as you want. * ``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. You can have as many values as you want.
* ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list. * ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list.
* ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.
* ``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. * ``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.
* ``print(a, b, ...)`` -- prints the arguments to standard output. Unless you start calibre from the command line (``calibre-debug -g``), the output will go to a black hole. * ``print(a, b, ...)`` -- prints the arguments to standard output. Unless you start calibre from the command line (``calibre-debug -g``), the output will go to a black hole.
* ``raw_field(name)`` -- returns the metadata field named by name without applying any formatting. * ``raw_field(name)`` -- returns the metadata field named by name without applying any formatting.
@ -277,7 +278,7 @@ Function classification summary:
* Relational: ``cmp`` , ``strcmp`` for strings * Relational: ``cmp`` , ``strcmp`` for strings
* String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize`` * String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize``
* String manipulation: ``re``, ``shorten``, ``substr`` * String manipulation: ``re``, ``shorten``, ``substr``
* Other: ``assign``, ``booksize``, ``print``, ``format_date``, * Other: ``assign``, ``booksize``, ``format_date``, ``ondevice`` ``print``
.. _general_mode: .. _general_mode:

View File

@ -568,7 +568,7 @@ class BuiltinCapitalize(BuiltinFormatterFunction):
class BuiltinBooksize(BuiltinFormatterFunction): class BuiltinBooksize(BuiltinFormatterFunction):
name = 'booksize' name = 'booksize'
arg_count = 0 arg_count = 0
doc = _('booksize() -- return value of the field capitalized') doc = _('booksize() -- return value of the size field')
def evaluate(self, formatter, kwargs, mi, locals): def evaluate(self, formatter, kwargs, mi, locals):
if mi.book_size is not None: if mi.book_size is not None:
@ -578,6 +578,21 @@ class BuiltinBooksize(BuiltinFormatterFunction):
pass pass
return '' return ''
class BuiltinOndevice(BuiltinFormatterFunction):
name = 'ondevice'
arg_count = 0
doc = _('ondevice() -- return Yes if ondevice is set, otherwise return '
'the empty string')
def evaluate(self, formatter, kwargs, mi, locals):
print mi.ondevice_col
if mi.ondevice_col:
try:
return _('Yes')
except:
pass
return ''
class BuiltinFirstNonEmpty(BuiltinFormatterFunction): class BuiltinFirstNonEmpty(BuiltinFormatterFunction):
name = 'first_non_empty' name = 'first_non_empty'
arg_count = -1 arg_count = -1
@ -687,6 +702,7 @@ builtin_lowercase = BuiltinLowercase()
builtin_merge_lists = BuiltinMergeLists() builtin_merge_lists = BuiltinMergeLists()
builtin_multiply = BuiltinMultiply() builtin_multiply = BuiltinMultiply()
builtin_not = BuiltinNot() builtin_not = BuiltinNot()
builtin_ondevice = BuiltinOndevice()
builtin_or = BuiltinOr() builtin_or = BuiltinOr()
builtin_print = BuiltinPrint() builtin_print = BuiltinPrint()
builtin_raw_field = BuiltinRaw_field() builtin_raw_field = BuiltinRaw_field()