mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
1) add two tweaks controlling what custom fields the content server displays
2) add & cleanup some field_metadata methods
This commit is contained in:
parent
97e2c838d0
commit
8b9b64a8e6
@ -145,6 +145,24 @@ add_new_book_tags_when_importing_books = False
|
|||||||
# Set the maximum number of tags to show per book in the content server
|
# Set the maximum number of tags to show per book in the content server
|
||||||
max_content_server_tags_shown=5
|
max_content_server_tags_shown=5
|
||||||
|
|
||||||
|
# Set custom metadata fields that the content server will or will not display.
|
||||||
|
# content_server_will_display is a list of custom fields to be displayed.
|
||||||
|
# content_server_wont_display is a list of custom fields not to be displayed.
|
||||||
|
# wont_display has priority over will_display.
|
||||||
|
# The special value '*' means all custom fields.
|
||||||
|
# Defaults:
|
||||||
|
# content_server_will_display = ['*']
|
||||||
|
# content_server_wont_display = ['']
|
||||||
|
# Examples:
|
||||||
|
# To display only the custom fields #mytags and #genre:
|
||||||
|
# content_server_will_display = ['#mytags', '#genre']
|
||||||
|
# content_server_wont_display = ['']
|
||||||
|
# To display all fields except #mycomments:
|
||||||
|
# content_server_will_display = ['*']
|
||||||
|
# content_server_wont_display['#mycomments']
|
||||||
|
content_server_will_display = ['*']
|
||||||
|
content_server_wont_display = ['']
|
||||||
|
|
||||||
|
|
||||||
# Set the maximum number of sort 'levels' that calibre will use to resort the
|
# Set the maximum number of sort 'levels' that calibre will use to resort the
|
||||||
# library after certain operations such as searches or device insertion. Each
|
# library after certain operations such as searches or device insertion. Each
|
||||||
|
@ -132,7 +132,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
|
|
||||||
def set_database(self, db):
|
def set_database(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.custom_columns = self.db.field_metadata.get_custom_field_metadata()
|
self.custom_columns = self.db.field_metadata.custom_field_metadata()
|
||||||
self.column_map = list(self.orig_headers.keys()) + \
|
self.column_map = list(self.orig_headers.keys()) + \
|
||||||
list(self.custom_columns)
|
list(self.custom_columns)
|
||||||
def col_idx(name):
|
def col_idx(name):
|
||||||
|
@ -554,6 +554,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
def search_term_to_field_key(self, term):
|
def search_term_to_field_key(self, term):
|
||||||
return self.field_metadata.search_term_to_key(term)
|
return self.field_metadata.search_term_to_key(term)
|
||||||
|
|
||||||
|
def custom_field_metadata(self):
|
||||||
|
return self.field_metadata.custom_field_metadata()
|
||||||
|
|
||||||
|
def all_metadata(self):
|
||||||
|
return self.field_metadata.all_metadata()
|
||||||
|
|
||||||
def metadata_for_field(self, key):
|
def metadata_for_field(self, key):
|
||||||
return self.field_metadata[key]
|
return self.field_metadata[key]
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ class FieldMetadata(dict):
|
|||||||
l[k] = self._tb_cats[k]
|
l[k] = self._tb_cats[k]
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def get_custom_field_metadata(self):
|
def custom_field_metadata(self):
|
||||||
l = {}
|
l = {}
|
||||||
for k in self._tb_cats:
|
for k in self._tb_cats:
|
||||||
if self._tb_cats[k]['is_custom']:
|
if self._tb_cats[k]['is_custom']:
|
||||||
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.utils.config import Config, StringConfig, config_dir
|
from calibre.utils.config import Config, StringConfig, config_dir, tweaks
|
||||||
|
|
||||||
|
|
||||||
listen_on = '0.0.0.0'
|
listen_on = '0.0.0.0'
|
||||||
@ -46,6 +46,16 @@ def server_config(defaults=None):
|
|||||||
'to disable grouping.'))
|
'to disable grouping.'))
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
def custom_fields_to_display(db):
|
||||||
|
ckeys = db.custom_field_keys()
|
||||||
|
yes_fields = set(tweaks['content_server_will_display'])
|
||||||
|
no_fields = set(tweaks['content_server_wont_display'])
|
||||||
|
if '*' in yes_fields:
|
||||||
|
yes_fields = set(ckeys)
|
||||||
|
if '*' in no_fields:
|
||||||
|
no_fields = set(ckeys)
|
||||||
|
return frozenset(yes_fields - no_fields)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from calibre.library.server.main import main
|
from calibre.library.server.main import main
|
||||||
return main()
|
return main()
|
||||||
|
@ -13,6 +13,7 @@ from lxml import html
|
|||||||
from lxml.html.builder import HTML, HEAD, TITLE, LINK, DIV, IMG, BODY, \
|
from lxml.html.builder import HTML, HEAD, TITLE, LINK, DIV, IMG, BODY, \
|
||||||
OPTION, SELECT, INPUT, FORM, SPAN, TABLE, TR, TD, A, HR
|
OPTION, SELECT, INPUT, FORM, SPAN, TABLE, TR, TD, A, HR
|
||||||
|
|
||||||
|
from calibre.library.server import custom_fields_to_display
|
||||||
from calibre.library.server.utils import strftime, format_tag_string
|
from calibre.library.server.utils import strftime, format_tag_string
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.constants import __appname__
|
from calibre.constants import __appname__
|
||||||
@ -197,7 +198,7 @@ class MobileServer(object):
|
|||||||
self.sort(items, sort, (order.lower().strip() == 'ascending'))
|
self.sort(items, sort, (order.lower().strip() == 'ascending'))
|
||||||
|
|
||||||
CFM = self.db.field_metadata
|
CFM = self.db.field_metadata
|
||||||
CKEYS = [key for key in sorted(CFM.get_custom_fields(),
|
CKEYS = [key for key in sorted(custom_fields_to_display(self.db),
|
||||||
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
||||||
CFM[y]['name'].lower()))]
|
CFM[y]['name'].lower()))]
|
||||||
# This method uses its own book dict, not the Metadata dict. The loop
|
# This method uses its own book dict, not the Metadata dict. The loop
|
||||||
|
@ -17,6 +17,7 @@ import routes
|
|||||||
from calibre.constants import __appname__
|
from calibre.constants import __appname__
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
|
from calibre.library.server import custom_fields_to_display
|
||||||
from calibre.library.server.utils import format_tag_string
|
from calibre.library.server.utils import format_tag_string
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from calibre.utils.ordered_dict import OrderedDict
|
from calibre.utils.ordered_dict import OrderedDict
|
||||||
@ -277,7 +278,7 @@ class AcquisitionFeed(NavFeed):
|
|||||||
db):
|
db):
|
||||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
||||||
CFM = db.field_metadata
|
CFM = db.field_metadata
|
||||||
CKEYS = [key for key in sorted(CFM.get_custom_fields(),
|
CKEYS = [key for key in sorted(custom_fields_to_display(db),
|
||||||
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
||||||
CFM[y]['name'].lower()))]
|
CFM[y]['name'].lower()))]
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -11,6 +11,7 @@ import cherrypy
|
|||||||
from lxml.builder import ElementMaker
|
from lxml.builder import ElementMaker
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
|
from calibre.library.server import custom_fields_to_display
|
||||||
from calibre.library.server.utils import strftime, format_tag_string
|
from calibre.library.server.utils import strftime, format_tag_string
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
@ -94,7 +95,7 @@ class XMLServer(object):
|
|||||||
c = kwargs.pop('comments')
|
c = kwargs.pop('comments')
|
||||||
|
|
||||||
CFM = self.db.field_metadata
|
CFM = self.db.field_metadata
|
||||||
CKEYS = [key for key in sorted(CFM.get_custom_fields(),
|
CKEYS = [key for key in sorted(custom_fields_to_display(self.db),
|
||||||
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
||||||
CFM[y]['name'].lower()))]
|
CFM[y]['name'].lower()))]
|
||||||
custcols = []
|
custcols = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user