mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Start work on legacy custom column API
This commit is contained in:
parent
70f338b047
commit
62d1dfbeef
@ -549,6 +549,7 @@ class DB(object):
|
|||||||
|
|
||||||
# Load metadata for custom columns
|
# Load metadata for custom columns
|
||||||
self.custom_column_label_map, self.custom_column_num_map = {}, {}
|
self.custom_column_label_map, self.custom_column_num_map = {}, {}
|
||||||
|
self.custom_column_num_to_label_map = {}
|
||||||
triggers = []
|
triggers = []
|
||||||
remove = []
|
remove = []
|
||||||
custom_tables = self.custom_tables
|
custom_tables = self.custom_tables
|
||||||
@ -586,6 +587,7 @@ class DB(object):
|
|||||||
|
|
||||||
self.custom_column_num_map[data['num']] = \
|
self.custom_column_num_map[data['num']] = \
|
||||||
self.custom_column_label_map[data['label']] = data
|
self.custom_column_label_map[data['label']] = data
|
||||||
|
self.custom_column_num_to_label_map[data['num']] = data['label']
|
||||||
|
|
||||||
# Create Foreign Key triggers
|
# Create Foreign Key triggers
|
||||||
if data['normalized']:
|
if data['normalized']:
|
||||||
@ -785,6 +787,11 @@ class DB(object):
|
|||||||
self._conn = Connection(self.dbpath)
|
self._conn = Connection(self.dbpath)
|
||||||
return self._conn
|
return self._conn
|
||||||
|
|
||||||
|
def custom_field_name(self, label=None, num=None):
|
||||||
|
if label is not None:
|
||||||
|
return self.field_metadata.custom_field_prefix + label
|
||||||
|
return self.field_metadata.custom_field_prefix + self.custom_column_num_to_label_map[num]
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self._conn is not None:
|
if self._conn is not None:
|
||||||
self._conn.close()
|
self._conn.close()
|
||||||
|
@ -70,6 +70,7 @@ class LibraryDatabase(object):
|
|||||||
setattr(self, x, getattr(self.data, x))
|
setattr(self, x, getattr(self.data, x))
|
||||||
|
|
||||||
self.is_case_sensitive = getattr(backend, 'is_case_sensitive', False)
|
self.is_case_sensitive = getattr(backend, 'is_case_sensitive', False)
|
||||||
|
self.custom_field_name = backend.custom_field_name
|
||||||
|
|
||||||
self.last_update_check = self.last_modified()
|
self.last_update_check = self.last_modified()
|
||||||
|
|
||||||
@ -638,6 +639,7 @@ for field in ('authors', 'tags', 'publisher', 'series'):
|
|||||||
name = field[:-1] if field in {'authors', 'tags'} else field
|
name = field[:-1] if field in {'authors', 'tags'} else field
|
||||||
setattr(LibraryDatabase, 'all_%s_names' % name, MT(getter(field)))
|
setattr(LibraryDatabase, 'all_%s_names' % name, MT(getter(field)))
|
||||||
LibraryDatabase.all_formats = MT(lambda self:self.new_api.all_field_names('formats'))
|
LibraryDatabase.all_formats = MT(lambda self:self.new_api.all_field_names('formats'))
|
||||||
|
LibraryDatabase.all_custom = MT(lambda self, label=None, num=None:self.new_api.all_field_names(self.custom_field_name(label, num)))
|
||||||
|
|
||||||
for func, field in {'all_authors':'authors', 'all_titles':'title', 'all_tags2':'tags', 'all_series':'series', 'all_publishers':'publisher'}.iteritems():
|
for func, field in {'all_authors':'authors', 'all_titles':'title', 'all_tags2':'tags', 'all_series':'series', 'all_publishers':'publisher'}.iteritems():
|
||||||
def getter(field):
|
def getter(field):
|
||||||
|
@ -604,7 +604,17 @@ class LegacyTest(BaseTest):
|
|||||||
))
|
))
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
def test_legacy_custom(self): # {{{
|
||||||
|
'Test the legacy API for custom columns'
|
||||||
|
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'),
|
||||||
|
))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user