diff --git a/src/calibre/srv/handler.py b/src/calibre/srv/handler.py index 39f98f7a52..595310c93f 100644 --- a/src/calibre/srv/handler.py +++ b/src/calibre/srv/handler.py @@ -89,6 +89,13 @@ class Context(object): self.testing = testing self.lock = Lock() self.user_manager = UserManager(opts.userdb) + self.ignored_fields = frozenset(filter(None, (x.strip() for x in (opts.ignored_fields or '').split(',')))) + self.displayed_fields = frozenset(filter(None, (x.strip() for x in (opts.displayed_fields or '').split(',')))) + + def is_field_displayable(self, field): + if self.displayed_fields and field not in self.displayed_fields: + return False + return field not in self.ignored_fields def init_session(self, endpoint, data): pass diff --git a/src/calibre/srv/opds.py b/src/calibre/srv/opds.py index 8d5c6daf79..7605c67674 100644 --- a/src/calibre/srv/opds.py +++ b/src/calibre/srv/opds.py @@ -181,7 +181,7 @@ def ACQUISITION_ENTRY(book_id, updated, request_context): extra.append(_('SERIES: %(series)s [%(sidx)s]
')% dict(series=xml(mi.series), sidx=fmt_sidx(float(mi.series_index)))) - for key in field_metadata.ignorable_field_keys(): + for key in filter(request_context.ctx.is_field_displayable, field_metadata.ignorable_field_keys()): name, val = mi.format_field(key) if val: fm = field_metadata[key] diff --git a/src/calibre/srv/opts.py b/src/calibre/srv/opts.py index 3b21af34c0..200f6d2478 100644 --- a/src/calibre/srv/opts.py +++ b/src/calibre/srv/opts.py @@ -124,9 +124,21 @@ raw_options = ( _('Set the HTTP authentication mode used by the server. Set to "basic" is you are' ' putting this server behind an SSL proxy. Otherwise, leave it as "auto", which' ' will use "basic" if SSL is configured otherwise it will use "digest".'), + + _('Ignored user-defined metadata fields'), + 'ignored_fields', None, + _('Comma separated list of user-defined metadata fields that will not be displayed' + ' by the content server in the /opds and /mobile views.'), + + _('Only display user-defined fields'), + 'displayed_fields', None, + _('Comma separated list of user-defined metadata fields that will be displayed' + ' by the content server in the /opds and /mobile views. If you specify this' + ' option, any fields not in this list will not be displayed.'), + + ) assert len(raw_options) % 4 == 0 -# TODO: Mark these strings for translation, once you finalize the option set options = []