mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Add limit to number of tags that display in content server
2) Add tweak to set the limit.
This commit is contained in:
parent
7ea0e19840
commit
f383f6ee5c
@ -50,7 +50,7 @@ function render_book(book) {
|
||||
var comments = $.trim(book.text()).replace(/\n\n/, '<br/>');
|
||||
var formats = new Array();
|
||||
var size = (parseFloat(book.attr('size'))/(1024*1024)).toFixed(1);
|
||||
var tags = book.attr('tags').replace(/,/g, ', ');
|
||||
var tags = book.attr('tags')
|
||||
formats = book.attr("formats").split(",");
|
||||
if (formats.length > 0) {
|
||||
for (i=0; i < formats.length; i++) {
|
||||
|
@ -110,3 +110,6 @@ grouped_search_terms = {}
|
||||
# a book' are added when copying books to another library
|
||||
add_new_book_tags_when_importing_books = False
|
||||
|
||||
|
||||
# Set the maximum number of tags to show in the content server
|
||||
max_content_server_tags_shown=5
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
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'
|
||||
@ -49,3 +49,15 @@ def server_config(defaults=None):
|
||||
def main():
|
||||
from calibre.library.server.main import main
|
||||
return main()
|
||||
|
||||
def format_tag_string(tags, sep):
|
||||
MAX = tweaks['max_content_server_tags_shown']
|
||||
if tags:
|
||||
tlist = [t.strip() for t in tags.split(sep)]
|
||||
else:
|
||||
tlist = []
|
||||
tlist.sort(cmp=lambda x,y:cmp(x.lower(), y.lower()))
|
||||
if len(tlist) > MAX:
|
||||
tlist = tlist[:MAX]+['...']
|
||||
return u'%s'%(', '.join(tlist)) if tlist else ''
|
||||
|
||||
|
@ -18,6 +18,7 @@ from calibre.ebooks.metadata import fmt_sidx
|
||||
from calibre.constants import __appname__
|
||||
from calibre import human_readable
|
||||
from calibre.utils.date import utcfromtimestamp, format_date
|
||||
from . import format_tag_string
|
||||
|
||||
def CLASS(*args, **kwargs): # class is a reserved word in Python
|
||||
kwargs['class'] = ' '.join(args)
|
||||
@ -213,7 +214,7 @@ class MobileServer(object):
|
||||
book['authors'] = authors
|
||||
book['series_index'] = fmt_sidx(float(record[FM['series_index']]))
|
||||
book['series'] = record[FM['series']]
|
||||
book['tags'] = record[FM['tags']]
|
||||
book['tags'] = format_tag_string(record[FM['tags']], ',')
|
||||
book['title'] = record[FM['title']]
|
||||
for x in ('timestamp', 'pubdate'):
|
||||
book[x] = strftime('%Y/%m/%d %H:%M:%S', record[FM[x]])
|
||||
@ -229,7 +230,7 @@ class MobileServer(object):
|
||||
continue
|
||||
name = CFM[key]['name']
|
||||
if datatype == 'text' and CFM[key]['is_multiple']:
|
||||
book[key] = concat(name, ','.join(val.split('|')))
|
||||
book[key] = concat(name, format_tag_string(val, '|'))
|
||||
elif datatype == 'series':
|
||||
book[key] = concat(name, '%s [%s]'%(val,
|
||||
fmt_sidx(record[CFM.cc_series_index_column_for(key)])))
|
||||
|
@ -16,6 +16,7 @@ from calibre.ebooks.metadata import fmt_sidx
|
||||
from calibre.constants import preferred_encoding
|
||||
from calibre import isbytestring
|
||||
from calibre.utils.date import format_date
|
||||
from . import format_tag_string
|
||||
|
||||
E = ElementMaker()
|
||||
|
||||
@ -84,6 +85,8 @@ class XMLServer(object):
|
||||
for x in ('isbn', 'formats', 'series', 'tags', 'publisher',
|
||||
'comments'):
|
||||
y = record[FM[x]]
|
||||
if x == 'tags':
|
||||
y = format_tag_string(y, ',')
|
||||
kwargs[x] = serialize(y) if y else ''
|
||||
|
||||
c = kwargs.pop('comments')
|
||||
@ -105,7 +108,7 @@ class XMLServer(object):
|
||||
name = CFM[key]['name']
|
||||
custcols.append(k)
|
||||
if datatype == 'text' and CFM[key]['is_multiple']:
|
||||
kwargs[k] = concat(name, ','.join(val.split('|')))
|
||||
kwargs[k] = concat(name, format_tag_string(val,'|'))
|
||||
elif datatype == 'series':
|
||||
kwargs[k] = concat(name, '%s [%s]'%(val,
|
||||
fmt_sidx(record[CFM.cc_series_index_column_for(key)])))
|
||||
|
Loading…
x
Reference in New Issue
Block a user