all_formats()

This commit is contained in:
Kovid Goyal 2013-07-12 13:39:14 +05:30
parent c1cca5213a
commit 998a79075c
3 changed files with 5 additions and 0 deletions

View File

@ -363,6 +363,9 @@ class Cache(object):
@read_api
def all_field_names(self, field):
''' Frozen set of all fields names (should only be used for many-one and many-many fields) '''
if field == 'formats':
return frozenset(self.fields[field].table.col_book_map)
try:
return frozenset(self.fields[field].table.id_map.itervalues())
except AttributeError:

View File

@ -68,6 +68,7 @@ class LibraryDatabase(object):
for field in ('authors', 'tags', 'publisher', 'series'):
name = field[:-1] if field in {'authors', 'tags'} else field
setattr(self, 'all_%s_names' % name, partial(self.new_api.all_field_names, field))
self.all_formats = partial(self.new_api.all_field_names, 'formats')
for func, field in {'all_authors':'authors', 'all_titles':'title', 'all_tags2':'tags', 'all_series':'series', 'all_publishers':'publisher'}.iteritems():
setattr(self, func, partial(self.field_id_map, field))

View File

@ -158,6 +158,7 @@ class LegacyTest(BaseTest):
'custom_field_keys':[(True,), (False,)],
'get_usage_count_by_id':[('authors',), ('tags',), ('series',), ('publisher',), ('#tags',), ('languages',)],
'get_field':[(1, 'title'), (2, 'tags'), (0, 'rating'), (1, 'authors'), (2, 'series'), (1, '#tags')],
'all_formats':[()],
}.iteritems():
for a in args:
fmt = lambda x: x