This commit is contained in:
Kovid Goyal 2022-12-18 17:08:27 +05:30
commit 74b9f66d02
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 8 deletions

View File

@ -2350,11 +2350,18 @@ class Cache:
return self._books_for_field(f.name, int(item_id_or_composite_value)) return self._books_for_field(f.name, int(item_id_or_composite_value))
@read_api @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) fm = self.field_metadata.get(f, None)
if fm and fm['datatype'] == 'composite' and fm['is_multiple']: if fm and fm['datatype'] == 'composite' and fm['is_multiple']:
return [v.strip() for v in v.split(',') if v.strip()] sep = fm['is_multiple'].get('cache_to_list', ',')
return v return (list(set(v.strip() for v in val.split(sep) if v.strip())))
return val
@read_api @read_api
def data_for_find_identical_books(self): def data_for_find_identical_books(self):

View File

@ -542,10 +542,7 @@ class Quickview(QDialog, Ui_Quickview):
self.books_table.setRowCount(0) self.books_table.setRowCount(0)
mi = self.db.new_api.get_proxy_metadata(book_id) mi = self.db.new_api.get_proxy_metadata(book_id)
vals = mi.get(key, None) vals = self.db.new_api.split_if_is_multiple_composite(key, 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()]
try: try:
# Check if we are in the GridView and there are no values for the # Check if we are in the GridView and there are no values for the
# selected column. In this case switch the column to 'authors' # selected column. In this case switch the column to 'authors'

View File

@ -773,7 +773,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
def __init__(self, parent): def __init__(self, parent):
''' '''
Delegate for custom_column bool data. Delegate for composite custom_columns.
''' '''
QStyledItemDelegate.__init__(self, parent) QStyledItemDelegate.__init__(self, parent)
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist'] self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']