get_custome_items_with_ids()

This commit is contained in:
Kovid Goyal 2013-07-16 22:35:23 +05:30
parent 62d1dfbeef
commit 7ceedb4e3c
2 changed files with 12 additions and 6 deletions

View File

@ -150,6 +150,12 @@ class LibraryDatabase(object):
def field_id_map(self, field): def field_id_map(self, field):
return [(k, v) for k, v in self.new_api.get_id_map(field).iteritems()] return [(k, v) for k, v in self.new_api.get_id_map(field).iteritems()]
def get_custom_items_with_ids(self, label=None, num=None):
try:
return [[k, v] for k, v in self.new_api.get_id_map(self.custom_field_name(label, num)).iteritems()]
except ValueError:
return []
def refresh(self, field=None, ascending=True): def refresh(self, field=None, ascending=True):
self.data.refresh(field=field, ascending=ascending) self.data.refresh(field=field, ascending=ascending)

View File

@ -48,9 +48,10 @@ def run_funcs(self, db, ndb, funcs):
meth(*args) meth(*args)
else: else:
fmt = lambda x:x fmt = lambda x:x
if meth[0] in {'!', '@', '#', '+'}: if meth[0] in {'!', '@', '#', '+', '$'}:
if meth[0] != '+': if meth[0] != '+':
fmt = {'!':dict, '@':lambda x:frozenset(x or ()), '#':lambda x:set((x or '').split(','))}[meth[0]] fmt = {'!':dict, '@':lambda x:frozenset(x or ()), '#':lambda x:set((x or '').split(',')),
'$':lambda x:set(tuple(y) for y in x)}[meth[0]]
else: else:
fmt = args[-1] fmt = args[-1]
args = args[:-1] args = args[:-1]
@ -611,10 +612,9 @@ class LegacyTest(BaseTest):
ndb = self.init_legacy(self.cloned_library) ndb = self.init_legacy(self.cloned_library)
db = self.init_old(self.cloned_library) db = self.init_old(self.cloned_library)
run_funcs(self, db, ndb, ( run_funcs(self, db, ndb, (
('all_custom', 'series'), ('all_custom', 'series'), ('all_custom', 'tags'), ('all_custom', 'rating'), ('all_custom', 'authors'),
('all_custom', 'tags'), ('$get_custom_items_with_ids', 'series'), ('$get_custom_items_with_ids', 'tags'), ('$get_custom_items_with_ids', 'float'),
('all_custom', 'rating'), ('$get_custom_items_with_ids', 'rating'), ('$get_custom_items_with_ids', 'authors'),
('all_custom', 'authors'),
)) ))
# }}} # }}}