From ea3719c7737b4c4df60840ed0b86bed872e07a6c Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 12 Sep 2010 20:52:26 +0100 Subject: [PATCH] Content server fixes --- src/calibre/library/server/mobile.py | 8 ++++++-- src/calibre/library/server/opds.py | 10 +++++++--- src/calibre/library/server/utils.py | 7 +++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index 6e08581aed..ab5b39eed8 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -124,6 +124,7 @@ def build_index(books, num, search, sort, order, start, total, url_base, CKEYS): series = u'[%s - %s]'%(book['series'], book['series_index']) \ if book['series'] else '' tags = u'Tags=[%s]'%book['tags'] if book['tags'] else '' + print tags ctext = '' for key in CKEYS: @@ -217,7 +218,8 @@ class MobileServer(object): book['authors'] = authors book['series_index'] = fmt_sidx(float(record[FM['series_index']])) book['series'] = record[FM['series']] - book['tags'] = format_tag_string(record[FM['tags']], ',') + book['tags'] = format_tag_string(record[FM['tags']], ',', + no_tag_count=True) book['title'] = record[FM['title']] for x in ('timestamp', 'pubdate'): book[x] = strftime('%Y/%m/%d %H:%M:%S', record[FM[x]]) @@ -233,7 +235,9 @@ class MobileServer(object): continue name = CFM[key]['name'] if datatype == 'text' and CFM[key]['is_multiple']: - book[key] = concat(name, format_tag_string(val, '|')) + book[key] = concat(name, + format_tag_string(val, '|', + no_tag_count=True)) 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/opds.py b/src/calibre/library/server/opds.py index c3a1d68749..e495598a2f 100644 --- a/src/calibre/library/server/opds.py +++ b/src/calibre/library/server/opds.py @@ -17,6 +17,7 @@ import routes from calibre.constants import __appname__ from calibre.ebooks.metadata import fmt_sidx from calibre.library.comments import comments_to_html +from calibre.library.server.utils import format_tag_string from calibre import guess_type from calibre.utils.ordered_dict import OrderedDict from calibre.utils.date import format_date @@ -147,8 +148,9 @@ def ACQUISITION_ENTRY(item, version, FM, updated, CFM, CKEYS): extra.append(_('RATING: %s
')%rating) tags = item[FM['tags']] if tags: - extra.append(_('TAGS: %s
')%\ - ', '.join(tags.split(','))) + extra.append(_('TAGS: %s
')%format_tag_string(tags, ',', + ignore_max=True, + no_tag_count=True)) series = item[FM['series']] if series: extra.append(_('SERIES: %s [%s]
')%\ @@ -160,7 +162,9 @@ def ACQUISITION_ENTRY(item, version, FM, updated, CFM, CKEYS): name = CFM[key]['name'] datatype = CFM[key]['datatype'] if datatype == 'text' and CFM[key]['is_multiple']: - extra.append('%s: %s
'%(name, ', '.join(val.split('|')))) + extra.append('%s: %s
'%(name, format_tag_string(val, '|', + ignore_max=True, + no_tag_count=True))) elif datatype == 'series': extra.append('%s: %s [%s]
'%(name, val, fmt_sidx(item[CFM.cc_series_index_column_for(key)]))) diff --git a/src/calibre/library/server/utils.py b/src/calibre/library/server/utils.py index 373653c15f..9a64948a3d 100644 --- a/src/calibre/library/server/utils.py +++ b/src/calibre/library/server/utils.py @@ -44,7 +44,7 @@ def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None): except: return _strftime(fmt, nowf().timetuple()) -def format_tag_string(tags, sep, ignore_max=False): +def format_tag_string(tags, sep, ignore_max=False, no_tag_count=False): MAX = sys.maxint if ignore_max else tweaks['max_content_server_tags_shown'] if tags: tlist = [t.strip() for t in tags.split(sep)] @@ -53,6 +53,9 @@ def format_tag_string(tags, sep, ignore_max=False): tlist.sort(cmp=lambda x,y:cmp(x.lower(), y.lower())) if len(tlist) > MAX: tlist = tlist[:MAX]+['...'] - return u'%s:&:%s'%(tweaks['max_content_server_tags_shown'], + if no_tag_count: + return ', '.join(tlist) if tlist else '' + else: + return u'%s:&:%s'%(tweaks['max_content_server_tags_shown'], ', '.join(tlist)) if tlist else ''