Fix handling of recursive templates in ProxyMetadata

This commit is contained in:
Kovid Goyal 2013-07-24 14:09:46 +05:30
parent d0b1001ee7
commit 415dc21588
2 changed files with 14 additions and 1 deletions

View File

@ -12,7 +12,7 @@ from functools import wraps
from collections import MutableMapping, MutableSequence from collections import MutableMapping, MutableSequence
from copy import deepcopy from copy import deepcopy
from calibre.ebooks.metadata.book.base import Metadata, SIMPLE_GET, TOP_LEVEL_IDENTIFIERS, NULL_VALUES from calibre.ebooks.metadata.book.base import Metadata, SIMPLE_GET, TOP_LEVEL_IDENTIFIERS, NULL_VALUES, ALL_METADATA_FIELDS
from calibre.ebooks.metadata.book.formatter import SafeFormat from calibre.ebooks.metadata.book.formatter import SafeFormat
from calibre.utils.date import utcnow from calibre.utils.date import utcnow
@ -350,3 +350,8 @@ class ProxyMetadata(Metadata):
return field_metadata[field] return field_metadata[field]
return None return None
def all_field_keys(self):
um = ga(self, '_user_metadata')
return frozenset(ALL_METADATA_FIELDS.union(um.iterkeys()))

View File

@ -495,5 +495,13 @@ class ReadingTest(BaseTest):
self.assertEqual(mi.format_field(field), pmi.format_field(field), self.assertEqual(mi.format_field(field), pmi.format_field(field),
'Custom field format: %s not the same for book %s' % (field, book_id)) 'Custom field format: %s not the same for book %s' % (field, book_id))
# Test handling of recursive templates
cache.create_custom_column('comp2', 'comp2', 'composite', False, display={'composite_template':'{title}'})
cache.create_custom_column('comp1', 'comp1', 'composite', False, display={'composite_template':'foo{#comp2}'})
cache.close()
cache = self.init_cache()
mi, pmi = cache.get_metadata(1), cache.get_proxy_metadata(1)
self.assertEqual(mi.get('#comp1'), pmi.get('#comp1'))
# }}} # }}}