From 7ceedb4e3ce3356e893dc20d8b4b4a137c4ea5f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 Jul 2013 22:35:23 +0530 Subject: [PATCH] get_custome_items_with_ids() --- src/calibre/db/legacy.py | 6 ++++++ src/calibre/db/tests/legacy.py | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 9073ed05ae..4d29a6b18f 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -150,6 +150,12 @@ class LibraryDatabase(object): def field_id_map(self, field): 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): self.data.refresh(field=field, ascending=ascending) diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index 3e08274561..45d1367b4e 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -48,9 +48,10 @@ def run_funcs(self, db, ndb, funcs): meth(*args) else: fmt = lambda x:x - if meth[0] in {'!', '@', '#', '+'}: + if meth[0] in {'!', '@', '#', '+', '$'}: 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: fmt = args[-1] args = args[:-1] @@ -611,10 +612,9 @@ class LegacyTest(BaseTest): ndb = self.init_legacy(self.cloned_library) db = self.init_old(self.cloned_library) run_funcs(self, db, ndb, ( - ('all_custom', 'series'), - ('all_custom', 'tags'), - ('all_custom', 'rating'), - ('all_custom', 'authors'), + ('all_custom', 'series'), ('all_custom', 'tags'), ('all_custom', 'rating'), ('all_custom', 'authors'), + ('$get_custom_items_with_ids', 'series'), ('$get_custom_items_with_ids', 'tags'), ('$get_custom_items_with_ids', 'float'), + ('$get_custom_items_with_ids', 'rating'), ('$get_custom_items_with_ids', 'authors'), )) # }}}