mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-10-31 10:37:00 -04:00 
			
		
		
		
	Add template function 'is_marked()'
This commit is contained in:
		
							parent
							
								
									fa4713d1f3
								
							
						
					
					
						commit
						1af28bd3ba
					
				| @ -460,6 +460,9 @@ 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``. |     * ``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. |       Throws an exception if ``x`` is not a number. | ||||||
|     * ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string. |     * ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string. | ||||||
|  |     * ``is_marked()`` -- check whether the book is `marked` in calibre. If it is then return the value of the mark, | ||||||
|  |       either `true` (lower case) or the comma-separated list of named marks. Returns '' (the empty string) if the book is not marked. | ||||||
|  |       This function works only in the GUI. | ||||||
|     * ``list_contains(separator, pattern, found_val, ..., not_found_val)`` -- (Alias of ``in_list``) Interpret the field as a list |     * ``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, |       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, |       return `found_val`, otherwise return `not_found_val`. The `pattern` and `found_value` can be repeated as many times as desired, | ||||||
|  | |||||||
| @ -1228,6 +1228,27 @@ class BuiltinAnnotationCount(BuiltinFormatterFunction): | |||||||
|         return _('This function can be used only in the GUI') |         return _('This function can be used only in the GUI') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class BuiltinIsMarked(BuiltinFormatterFunction): | ||||||
|  |     name = 'is_marked' | ||||||
|  |     arg_count = 0 | ||||||
|  |     category = 'Get values from metadata' | ||||||
|  |     __doc__ = doc = _("is_marked() -- check whether the book is 'marked' in " | ||||||
|  |                       "calibre. If it is then return the value of the mark, " | ||||||
|  |                       "either 'true' or the comma-separated list of named " | ||||||
|  |                       "marks. Returns '' if the book is not marked.") | ||||||
|  | 
 | ||||||
|  |     def evaluate(self, formatter, kwargs, mi, locals): | ||||||
|  |         if hasattr(mi, '_proxy_metadata'): | ||||||
|  |             try: | ||||||
|  |                 from calibre.gui2.ui import get_gui | ||||||
|  |                 c = get_gui().current_db.data.get_marked(mi.id) | ||||||
|  |                 return c if c else '' | ||||||
|  |             except: | ||||||
|  |                 return _('Failed to get marked status') | ||||||
|  |             return '' | ||||||
|  |         return _('This function can be used only in the GUI') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class BuiltinSeriesSort(BuiltinFormatterFunction): | class BuiltinSeriesSort(BuiltinFormatterFunction): | ||||||
|     name = 'series_sort' |     name = 'series_sort' | ||||||
|     arg_count = 0 |     arg_count = 0 | ||||||
| @ -1925,7 +1946,7 @@ _formatter_builtins = [ | |||||||
|     BuiltinGlobals(), |     BuiltinGlobals(), | ||||||
|     BuiltinHasCover(), BuiltinHumanReadable(), BuiltinIdentifierInList(), |     BuiltinHasCover(), BuiltinHumanReadable(), BuiltinIdentifierInList(), | ||||||
|     BuiltinIfempty(), BuiltinLanguageCodes(), BuiltinLanguageStrings(), |     BuiltinIfempty(), BuiltinLanguageCodes(), BuiltinLanguageStrings(), | ||||||
|     BuiltinInList(), BuiltinListDifference(), BuiltinListEquals(), |     BuiltinInList(), BuiltinIsMarked(), BuiltinListDifference(), BuiltinListEquals(), | ||||||
|     BuiltinListIntersection(), BuiltinListitem(), BuiltinListRe(), |     BuiltinListIntersection(), BuiltinListitem(), BuiltinListRe(), | ||||||
|     BuiltinListReGroup(), BuiltinListSort(), BuiltinListSplit(), BuiltinListUnion(), |     BuiltinListReGroup(), BuiltinListSort(), BuiltinListSplit(), BuiltinListUnion(), | ||||||
|     BuiltinLookup(), |     BuiltinLookup(), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user