diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 80b925e770..d3164b5ae1 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2350,11 +2350,18 @@ class Cache: return self._books_for_field(f.name, int(item_id_or_composite_value)) @read_api - def split_if_is_multiple_composite(self, f, v): + def split_if_is_multiple_composite(self, f, val): + ''' + If f is a composite column lookup key and the column is is_multiple then + split v into unique non-empty values. The comparison is case sensitive. + Order is not preserved. Return a list() for compatibility with proxy + metadata field getters, for example tags. + ''' fm = self.field_metadata.get(f, None) if fm and fm['datatype'] == 'composite' and fm['is_multiple']: - return [v.strip() for v in v.split(',') if v.strip()] - return v + sep = fm['is_multiple'].get('cache_to_list', ',') + return (list(set(v.strip() for v in val.split(sep) if v.strip()))) + return val @read_api def data_for_find_identical_books(self): diff --git a/src/calibre/gui2/dialogs/quickview.py b/src/calibre/gui2/dialogs/quickview.py index 2a17db7c2d..3c77b86a12 100644 --- a/src/calibre/gui2/dialogs/quickview.py +++ b/src/calibre/gui2/dialogs/quickview.py @@ -542,10 +542,7 @@ class Quickview(QDialog, Ui_Quickview): self.books_table.setRowCount(0) mi = self.db.new_api.get_proxy_metadata(book_id) - vals = mi.get(key, None) - if self.fm[key]['datatype'] == 'composite' and self.fm[key]['is_multiple']: - sep = self.fm[key]['is_multiple'].get('cache_to_list', ',') - vals = [v.strip() for v in vals.split(sep) if v.strip()] + vals = self.db.new_api.split_if_is_multiple_composite(key, mi.get(key, None)) try: # Check if we are in the GridView and there are no values for the # selected column. In this case switch the column to 'authors' diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 4dcfc988b3..eb9ac48bf1 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -773,7 +773,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{ def __init__(self, parent): ''' - Delegate for custom_column bool data. + Delegate for composite custom_columns. ''' QStyledItemDelegate.__init__(self, parent) self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']