Add the ability to get the calibre field 'size' using a formatter function booksize()

This commit is contained in:
Charles Haley 2011-04-19 09:46:43 +01:00
parent 5312b49d85
commit 1e1b530113
3 changed files with 16 additions and 0 deletions

View File

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

View File

@ -230,6 +230,7 @@ The following functions are available in addition to those described in single-f
* ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers.
* ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression
* ``booksize()`` -- returns the value of the |app| 'size' field. Returns '' if there are no formats.
* ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``.
* ``divide(x, y)`` -- returns x / y. Throws an exception if either x or y are not numbers.
* ``field(name)`` -- returns the metadata field named by ``name``.

View File

@ -549,8 +549,22 @@ class BuiltinCapitalize(BuiltinFormatterFunction):
def evaluate(self, formatter, kwargs, mi, locals, val):
return capitalize(val)
class BuiltinBooksize(BuiltinFormatterFunction):
name = 'booksize'
arg_count = 0
doc = _('booksize() -- return value of the field capitalized')
def evaluate(self, formatter, kwargs, mi, locals):
if mi.book_size is not None:
try:
return str(mi.book_size)
except:
pass
return ''
builtin_add = BuiltinAdd()
builtin_assign = BuiltinAssign()
builtin_booksize = BuiltinBooksize()
builtin_capitalize = BuiltinCapitalize()
builtin_cmp = BuiltinCmp()
builtin_contains = BuiltinContains()