From fc93863c581c43808470a6d735a1a35fe0ddf2b4 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 1 Jul 2011 14:22:24 +0100 Subject: [PATCH] Add as_html option to composite column --- src/calibre/gui2/book_details.py | 8 ++++++++ src/calibre/gui2/preferences/create_custom_column.py | 5 ++++- src/calibre/gui2/preferences/create_custom_column.ui | 10 ++++++++++ src/calibre/library/server/browse.py | 4 +++- src/calibre/library/server/opds.py | 3 ++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 5d396e2e96..c1592a59fc 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -100,6 +100,14 @@ def render_data(mi, use_roman_numbers=True, all_fields=False): val = force_unicode(val) ans.append((field, u'%s'%comments_to_html(val))) + elif metadata['datatype'] == 'composite' and \ + metadata['display'].get('contains_html', False): + val = getattr(mi, field) + if val: + val = force_unicode(val) + ans.append((field, + u'%s%s'% + (name, comments_to_html(val)))) elif field == 'path': if mi.path: path = force_unicode(mi.path, filesystem_encoding) diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index d2f1786ab0..9238ab3039 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -127,6 +127,8 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): self.composite_sort_by.setCurrentIndex(sb) self.composite_make_category.setChecked( c['display'].get('make_category', False)) + self.composite_make_category.setChecked( + c['display'].get('contains_html', False)) elif ct == 'enumeration': self.enum_box.setText(','.join(c['display'].get('enum_values', []))) self.enum_colors.setText(','.join(c['display'].get('enum_colors', []))) @@ -179,7 +181,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): getattr(self, 'date_format_'+x).setVisible(col_type == 'datetime') getattr(self, 'number_format_'+x).setVisible(col_type in ['int', 'float']) for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label', - 'make_category'): + 'make_category', 'contains_html'): getattr(self, 'composite_'+x).setVisible(col_type in ['composite', '*composite']) for x in ('box', 'default_label', 'label', 'colors', 'colors_label'): getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration') @@ -257,6 +259,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): 'composite_sort': ['text', 'number', 'date', 'bool'] [self.composite_sort_by.currentIndex()], 'make_category': self.composite_make_category.isChecked(), + 'contains_html': self.composite_contains_html.isChecked(), } elif col_type == 'enumeration': if not unicode(self.enum_box.text()).strip(): diff --git a/src/calibre/gui2/preferences/create_custom_column.ui b/src/calibre/gui2/preferences/create_custom_column.ui index cedbfd72b8..e6729e9657 100644 --- a/src/calibre/gui2/preferences/create_custom_column.ui +++ b/src/calibre/gui2/preferences/create_custom_column.ui @@ -294,6 +294,16 @@ and end with <code>}</code> You can have text before and after the f + + + + If checked, this column will be displayed as HTML in book details and the content server + + + Show as HTML in book details + + + diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index c88813d6d9..79c714d2ab 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -795,7 +795,9 @@ class BrowseServer(object): list(mi.get_all_user_metadata(False).items()): if m['is_custom'] and field not in displayed_custom_fields: continue - if m['datatype'] == 'comments' or field == 'comments': + if m['datatype'] == 'comments' or field == 'comments' or ( + m['datatype'] == 'composite' and \ + m['display'].get('contains_html', False)): val = mi.get(field, '') if val and val.strip(): comments.append((m['name'], comments_to_html(val))) diff --git a/src/calibre/library/server/opds.py b/src/calibre/library/server/opds.py index 04300ea0e3..759a80b2f8 100644 --- a/src/calibre/library/server/opds.py +++ b/src/calibre/library/server/opds.py @@ -186,7 +186,8 @@ def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS, prefix): CFM[key]['is_multiple']['ui_to_list'], ignore_max=True, no_tag_count=True, joinval=CFM[key]['is_multiple']['list_to_ui'])))) - elif datatype == 'comments': + elif datatype == 'comments' or CFM[key]['datatype'] == 'composite' and \ + CFM[key]['display'].get('contains_html', False): extra.append('%s: %s
'%(xml(name), comments_to_html(unicode(val)))) else: extra.append('%s: %s
'%(xml(name), xml(unicode(val))))