mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Make get_components use precomputed values for composite columns. Improves performance and makes values computed with user-defined functions work.
This commit is contained in:
parent
7b5f14462a
commit
1423e94c13
@ -150,12 +150,21 @@ class Formatter(TemplateFormatter):
|
||||
traceback.print_exc()
|
||||
b = None
|
||||
if b is not None and b['datatype'] == 'composite':
|
||||
val = b.get('#value#', None)
|
||||
if val is not None:
|
||||
return val.replace('/', '_').replace('\\', '_')
|
||||
if key in self.composite_values:
|
||||
self.composite_values[key] = val
|
||||
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]
|
||||
try:
|
||||
# We really should not get here, but it is safer to try
|
||||
self.composite_values[key] = 'RECURSIVE_COMPOSITE FIELD (S2D) ' + key
|
||||
self.composite_values[key] = \
|
||||
self.vformat(b['display']['composite_template'],
|
||||
[], kwargs).replace('/', '_').replace('\\', '_')
|
||||
return self.composite_values[key]
|
||||
except Exception, e:
|
||||
return unicode(e)
|
||||
if key in kwargs:
|
||||
val = kwargs[key]
|
||||
if isinstance(val, list):
|
||||
@ -170,6 +179,13 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
||||
sanitize_func=ascii_filename, replace_whitespace=False,
|
||||
to_lowercase=False, safe_format=True):
|
||||
|
||||
# Note: the mi argument is assumed to be an instance of Metadata returned
|
||||
# by db.get_metadata(). Reason: the composite columns should have already
|
||||
# been evaluated, which get_metadata does. If the mi is something else and
|
||||
# if the template uses composite columns, then a best-efforts attempt is
|
||||
# made to evaluate them. This will fail if the template uses a user-defined
|
||||
# template function.
|
||||
|
||||
tsorder = tweaks['save_template_title_series_sorting']
|
||||
format_args = FORMAT_ARGS.copy()
|
||||
format_args.update(mi.all_non_none_fields())
|
||||
|
Loading…
x
Reference in New Issue
Block a user