mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle formatting of recursive compisite templates
This commit is contained in:
parent
fef738c53b
commit
ca0e8729d2
@ -106,18 +106,31 @@ class SafeFormat(TemplateFormatter):
|
||||
'''
|
||||
Provides a format function that substitutes '' for any missing value
|
||||
'''
|
||||
|
||||
composite_values = {}
|
||||
|
||||
def get_value(self, key, args, kwargs):
|
||||
try:
|
||||
b = self.book.get_user_metadata(key, False)
|
||||
key = key.lower()
|
||||
if b is not None and b['datatype'] == 'composite':
|
||||
return self.vformat(b['display']['composite_template'], [], kwargs)
|
||||
if key in self.composite_values:
|
||||
return self.composite_values[key]
|
||||
self.composite_values[key] = 'RECURSIVE_COMPOSITE FIELD (S2D) ' + key
|
||||
self.composite_values[key] = \
|
||||
self.vformat(b['display']['composite_template'], [], kwargs)
|
||||
return self.composite_values[key]
|
||||
if kwargs[key]:
|
||||
return self.sanitize(kwargs[key.lower()])
|
||||
return ''
|
||||
except:
|
||||
return ''
|
||||
|
||||
def safe_format(self, fmt, kwargs, error_value, book, sanitize=None):
|
||||
self.composite_values = {}
|
||||
return TemplateFormatter.safe_format(self, fmt, kwargs, error_value,
|
||||
book, sanitize)
|
||||
|
||||
safe_formatter = SafeFormat()
|
||||
|
||||
def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
||||
|
Loading…
x
Reference in New Issue
Block a user