From b689944a2f1147c19e141a2c452022994a3d8574 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 3 Feb 2013 16:21:08 +0100 Subject: [PATCH] make it possible not to include user categories (@foo) in content server field lists. --- src/calibre/library/field_metadata.py | 12 ++++++++++++ src/calibre/library/server/__init__.py | 2 +- src/calibre/library/server/ajax.py | 3 ++- src/calibre/library/server/browse.py | 8 +++++--- src/calibre/library/server/opds.py | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index cfe57aa11d..1e0dacb3b5 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -497,6 +497,18 @@ class FieldMetadata(dict): def is_custom_field(self, key): return key.startswith(self.custom_field_prefix) + def is_ignorable_field(self, key): + return self.is_custom_field(key) or key.startswith('@') + + def ignorable_field_keys(self): + res = [] + for k in self._tb_cats.keys(): + fm = self._tb_cats[k] + if fm['kind'] == 'user' or (fm['kind']=='field' and fm['is_custom'] and \ + (fm['datatype'] != 'composite')): + res.append(k) + return res + def is_series_index(self, key): m = self[key] return (m['datatype'] == 'float' and key.endswith('_index') and diff --git a/src/calibre/library/server/__init__.py b/src/calibre/library/server/__init__.py index 950c881d8d..56429c44d0 100644 --- a/src/calibre/library/server/__init__.py +++ b/src/calibre/library/server/__init__.py @@ -51,7 +51,7 @@ def server_config(defaults=None): return c def custom_fields_to_display(db): - ckeys = db.custom_field_keys() + ckeys = db.field_metadata.ignorable_field_keys() yes_fields = set(tweaks['content_server_will_display']) no_fields = set(tweaks['content_server_wont_display']) if '*' in yes_fields: diff --git a/src/calibre/library/server/ajax.py b/src/calibre/library/server/ajax.py index ac0c5bf1c1..05ddfc5015 100644 --- a/src/calibre/library/server/ajax.py +++ b/src/calibre/library/server/ajax.py @@ -300,7 +300,8 @@ class AjaxServer(object): meta = category_meta.get(category, None) if meta is None: continue - if meta['is_custom'] and category not in displayed_custom_fields: + if category_meta.is_ignorable_field(category) and \ + category not in displayed_custom_fields: continue display_name = meta['name'] if category.startswith('@'): diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index 7f648d14a0..1489d3562b 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -269,7 +269,7 @@ class BrowseServer(object): for x in fm.sortable_field_keys(): if x in ('ondevice', 'formats', 'sort'): continue - if fm[x]['is_custom'] and x not in displayed_custom_fields: + if fm.is_ignorable_field(x) and x not in displayed_custom_fields: continue if x == 'comments' or fm[x]['datatype'] == 'comments': continue @@ -369,7 +369,8 @@ class BrowseServer(object): meta = category_meta.get(category, None) if meta is None: continue - if meta['is_custom'] and category not in displayed_custom_fields: + if self.db.field_metadata.is_ignorable_field(category) and \ + category not in displayed_custom_fields: continue # get the icon files main_cat = (category.partition('.')[0]) if hasattr(category, @@ -836,7 +837,8 @@ class BrowseServer(object): displayed_custom_fields = custom_fields_to_display(self.db) for field, m in list(mi.get_all_standard_metadata(False).items()) + \ list(mi.get_all_user_metadata(False).items()): - if m['is_custom'] and field not in displayed_custom_fields: + if self.db.field_metadata.is_ignorable_field(field) and \ + field not in displayed_custom_fields: continue if m['datatype'] == 'comments' or field == 'comments' or ( m['datatype'] == 'composite' and \ diff --git a/src/calibre/library/server/opds.py b/src/calibre/library/server/opds.py index f74a0e6a17..36a65661d1 100644 --- a/src/calibre/library/server/opds.py +++ b/src/calibre/library/server/opds.py @@ -594,7 +594,7 @@ class OPDSServer(object): meta = category_meta.get(category, None) if meta is None: continue - if category_meta.is_custom_field(category) and \ + if category_meta.is_ignorable_field(category) and \ category not in custom_fields_to_display(self.db): continue cats.append((meta['name'], meta['name'], 'N'+category))