diff --git a/resources/content_server/gui.js b/resources/content_server/gui.js index 7dd056b959..8368866a5e 100644 --- a/resources/content_server/gui.js +++ b/resources/content_server/gui.js @@ -50,7 +50,7 @@ function render_book(book) { var comments = $.trim(book.text()).replace(/\n\n/, '
'); 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++) { diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index afbc6e7334..2897860ec4 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -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 \ No newline at end of file diff --git a/src/calibre/library/server/__init__.py b/src/calibre/library/server/__init__.py index 5050dfaa99..7b283be854 100644 --- a/src/calibre/library/server/__init__.py +++ b/src/calibre/library/server/__init__.py @@ -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 '' + diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index 6a0744c317..961c33fe79 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -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)]))) diff --git a/src/calibre/library/server/xml.py b/src/calibre/library/server/xml.py index 3897faf31e..8cfb45c66f 100644 --- a/src/calibre/library/server/xml.py +++ b/src/calibre/library/server/xml.py @@ -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)])))