mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
More CC API
This commit is contained in:
parent
6c1bcc6503
commit
dd5ccfd75c
@ -574,6 +574,21 @@ class LibraryDatabase(object):
|
|||||||
existing_tags = self.all_custom(label=label, num=num)
|
existing_tags = self.all_custom(label=label, num=num)
|
||||||
return icu_lower(item) in {icu_lower(t) for t in existing_tags}
|
return icu_lower(item) in {icu_lower(t) for t in existing_tags}
|
||||||
|
|
||||||
|
def delete_custom_item_using_id(self, item_id, label=None, num=None):
|
||||||
|
self.new_api.remove_items(self.custom_field_name(label, num), (item_id,))
|
||||||
|
|
||||||
|
def rename_custom_item(self, old_id, new_name, label=None, num=None):
|
||||||
|
self.new_api.rename_items(self.custom_field_name(label, num), {old_id:new_name}, change_index=False)
|
||||||
|
|
||||||
|
def delete_item_from_multiple(self, item, label=None, num=None):
|
||||||
|
field = self.custom_field_name(label, num)
|
||||||
|
existing = self.new_api.get_id_map(field)
|
||||||
|
rmap = {icu_lower(v):k for k, v in existing.iteritems()}
|
||||||
|
item_id = rmap.get(icu_lower(item), None)
|
||||||
|
if item_id is None:
|
||||||
|
return []
|
||||||
|
return list(self.new_api.remove_items(field, (item_id,)))
|
||||||
|
|
||||||
# Private interface {{{
|
# Private interface {{{
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for row in self.data.iterall():
|
for row in self.data.iterall():
|
||||||
|
@ -611,6 +611,7 @@ class LegacyTest(BaseTest):
|
|||||||
'Test the legacy API for custom columns'
|
'Test the legacy API for custom columns'
|
||||||
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)
|
||||||
|
# Test getting
|
||||||
run_funcs(self, db, ndb, (
|
run_funcs(self, db, ndb, (
|
||||||
('all_custom', 'series'), ('all_custom', 'tags'), ('all_custom', 'rating'), ('all_custom', 'authors'), ('all_custom', None, 7),
|
('all_custom', 'series'), ('all_custom', 'tags'), ('all_custom', 'rating'), ('all_custom', 'authors'), ('all_custom', None, 7),
|
||||||
('get_next_cc_series_num_for', 'My Series One', 'series'), ('get_next_cc_series_num_for', 'My Series Two', 'series'),
|
('get_next_cc_series_num_for', 'My Series One', 'series'), ('get_next_cc_series_num_for', 'My Series Two', 'series'),
|
||||||
@ -622,6 +623,26 @@ class LegacyTest(BaseTest):
|
|||||||
for label in ('tags', 'series', 'authors', 'comments', 'rating', 'date', 'yesno', 'isbn', 'enum', 'formats', 'float', 'comp_tags'):
|
for label in ('tags', 'series', 'authors', 'comments', 'rating', 'date', 'yesno', 'isbn', 'enum', 'formats', 'float', 'comp_tags'):
|
||||||
for func in ('get_custom', 'get_custom_extra', 'get_custom_and_extra'):
|
for func in ('get_custom', 'get_custom_extra', 'get_custom_and_extra'):
|
||||||
run_funcs(self, db, ndb, [(func, idx, label) for idx in range(3)])
|
run_funcs(self, db, ndb, [(func, idx, label) for idx in range(3)])
|
||||||
|
|
||||||
|
# Test renaming/deleting
|
||||||
|
t = {v:k for k, v in ndb.new_api.get_id_map('#tags').iteritems()}['My Tag One']
|
||||||
|
t2 = {v:k for k, v in ndb.new_api.get_id_map('#tags').iteritems()}['My Tag Two']
|
||||||
|
a = {v:k for k, v in ndb.new_api.get_id_map('#authors').iteritems()}['My Author Two']
|
||||||
|
a2 = {v:k for k, v in ndb.new_api.get_id_map('#authors').iteritems()}['Custom One']
|
||||||
|
s = {v:k for k, v in ndb.new_api.get_id_map('#series').iteritems()}['My Series One']
|
||||||
|
run_funcs(self, db, ndb, (
|
||||||
|
('delete_custom_item_using_id', t, 'tags'),
|
||||||
|
('delete_custom_item_using_id', a, 'authors'),
|
||||||
|
('rename_custom_item', t2, 't2', 'tags'),
|
||||||
|
('rename_custom_item', a2, 'custom one', 'authors'),
|
||||||
|
('rename_custom_item', s, 'My Series Two', 'series'),
|
||||||
|
('delete_item_from_multiple', 'custom two', 'authors'),
|
||||||
|
(db.clean,),
|
||||||
|
(db.refresh,),
|
||||||
|
('all_custom', 'series'), ('all_custom', 'tags'), ('all_custom', 'authors'),
|
||||||
|
))
|
||||||
|
for label in ('tags', 'authors', 'series'):
|
||||||
|
run_funcs(self, db, ndb, [('get_custom_and_extra', idx, label) for idx in range(3)])
|
||||||
db.close()
|
db.close()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user