Options to control which user defined metadata fields are rendered in /opds

This commit is contained in:
Kovid Goyal 2016-02-25 11:20:56 +05:30
parent c3b1b9fba9
commit 554c08a4ef
3 changed files with 21 additions and 2 deletions

View File

@ -89,6 +89,13 @@ class Context(object):
self.testing = testing self.testing = testing
self.lock = Lock() self.lock = Lock()
self.user_manager = UserManager(opts.userdb) 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): def init_session(self, endpoint, data):
pass pass

View File

@ -181,7 +181,7 @@ def ACQUISITION_ENTRY(book_id, updated, request_context):
extra.append(_('SERIES: %(series)s [%(sidx)s]<br />')% extra.append(_('SERIES: %(series)s [%(sidx)s]<br />')%
dict(series=xml(mi.series), dict(series=xml(mi.series),
sidx=fmt_sidx(float(mi.series_index)))) 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) name, val = mi.format_field(key)
if val: if val:
fm = field_metadata[key] fm = field_metadata[key]

View File

@ -124,9 +124,21 @@ raw_options = (
_('Set the HTTP authentication mode used by the server. Set to "basic" is you are' _('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' ' 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".'), ' 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 assert len(raw_options) % 4 == 0
# TODO: Mark these strings for translation, once you finalize the option set
options = [] options = []