mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add custom column information to standard and mobile versions of the content server
This commit is contained in:
parent
e28f8438b7
commit
c15f91812b
@ -59,7 +59,14 @@ function render_book(book) {
|
|||||||
title = title.slice(0, title.length-2);
|
title = title.slice(0, title.length-2);
|
||||||
title += ' ({0} MB) '.format(size);
|
title += ' ({0} MB) '.format(size);
|
||||||
}
|
}
|
||||||
if (tags) title += '[{0}]'.format(tags);
|
if (tags) title += 'Tags=[{0}] '.format(tags);
|
||||||
|
custcols = book.attr("custcols").split(',')
|
||||||
|
for ( i = 0; i < custcols.length; i++) {
|
||||||
|
if (custcols[i].length > 0) {
|
||||||
|
vals = book.attr(custcols[i]).split(':#:', 2);
|
||||||
|
title += '{0}=[{1}] '.format(vals[0], vals[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
title += '<img style="display:none" alt="" src="get/cover/{0}" /></span>'.format(id);
|
title += '<img style="display:none" alt="" src="get/cover/{0}" /></span>'.format(id);
|
||||||
title += '<div class="comments">{0}</div>'.format(comments)
|
title += '<div class="comments">{0}</div>'.format(comments)
|
||||||
// Render authors cell
|
// Render authors cell
|
||||||
@ -290,7 +297,7 @@ function layout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// document is ready
|
// document is ready
|
||||||
create_table_headers();
|
create_table_headers();
|
||||||
|
|
||||||
// Setup widgets
|
// Setup widgets
|
||||||
|
@ -17,7 +17,7 @@ from calibre.library.server.utils import strftime
|
|||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.constants import __appname__
|
from calibre.constants import __appname__
|
||||||
from calibre import human_readable
|
from calibre import human_readable
|
||||||
from calibre.utils.date import utcfromtimestamp
|
from calibre.utils.date import utcfromtimestamp, format_date
|
||||||
|
|
||||||
def CLASS(*args, **kwargs): # class is a reserved word in Python
|
def CLASS(*args, **kwargs): # class is a reserved word in Python
|
||||||
kwargs['class'] = ' '.join(args)
|
kwargs['class'] = ' '.join(args)
|
||||||
@ -85,7 +85,7 @@ def build_navigation(start, num, total, url_base): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def build_index(books, num, search, sort, order, start, total, url_base):
|
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS):
|
||||||
logo = DIV(IMG(src='/static/calibre.png', alt=__appname__), id='logo')
|
logo = DIV(IMG(src='/static/calibre.png', alt=__appname__), id='logo')
|
||||||
|
|
||||||
search_box = build_search_box(num, search, sort, order)
|
search_box = build_search_box(num, search, sort, order)
|
||||||
@ -123,10 +123,16 @@ def build_index(books, num, search, sort, order, start, total, url_base):
|
|||||||
|
|
||||||
series = u'[%s - %s]'%(book['series'], book['series_index']) \
|
series = u'[%s - %s]'%(book['series'], book['series_index']) \
|
||||||
if book['series'] else ''
|
if book['series'] else ''
|
||||||
tags = u'[%s]'%book['tags'] if book['tags'] else ''
|
tags = u'Tags=[%s]'%book['tags'] if book['tags'] else ''
|
||||||
|
|
||||||
text = u'\u202f%s %s by %s - %s - %s %s' % (book['title'], series,
|
ctext = ''
|
||||||
book['authors'], book['size'], book['timestamp'], tags)
|
for key in CKEYS:
|
||||||
|
val = book.get(key, None)
|
||||||
|
if val:
|
||||||
|
ctext += '%s=[%s] '%tuple(val.split(':#:'))
|
||||||
|
|
||||||
|
text = u'\u202f%s %s by %s - %s - %s %s %s' % (book['title'], series,
|
||||||
|
book['authors'], book['size'], book['timestamp'], tags, ctext)
|
||||||
|
|
||||||
if last is None:
|
if last is None:
|
||||||
data.text = text
|
data.text = text
|
||||||
@ -189,6 +195,10 @@ class MobileServer(object):
|
|||||||
if sort is not None:
|
if sort is not None:
|
||||||
self.sort(items, sort, (order.lower().strip() == 'ascending'))
|
self.sort(items, sort, (order.lower().strip() == 'ascending'))
|
||||||
|
|
||||||
|
CFM = self.db.field_metadata
|
||||||
|
CKEYS = [key for key in sorted(CFM.get_custom_fields(),
|
||||||
|
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
||||||
|
CFM[y]['name'].lower()))]
|
||||||
books = []
|
books = []
|
||||||
for record in items[(start-1):(start-1)+num]:
|
for record in items[(start-1):(start-1)+num]:
|
||||||
book = {'formats':record[FM['formats']], 'size':record[FM['size']]}
|
book = {'formats':record[FM['formats']], 'size':record[FM['size']]}
|
||||||
@ -209,6 +219,31 @@ class MobileServer(object):
|
|||||||
book[x] = strftime('%Y/%m/%d %H:%M:%S', record[FM[x]])
|
book[x] = strftime('%Y/%m/%d %H:%M:%S', record[FM[x]])
|
||||||
book['id'] = record[FM['id']]
|
book['id'] = record[FM['id']]
|
||||||
books.append(book)
|
books.append(book)
|
||||||
|
for key in CKEYS:
|
||||||
|
def concat(name, val):
|
||||||
|
return '%s:#:%s'%(name, unicode(val))
|
||||||
|
val = record[CFM[key]['rec_index']]
|
||||||
|
if val:
|
||||||
|
datatype = CFM[key]['datatype']
|
||||||
|
if datatype in ['comments']:
|
||||||
|
continue
|
||||||
|
name = CFM[key]['name']
|
||||||
|
if datatype == 'text' and CFM[key]['is_multiple']:
|
||||||
|
book[key] = concat(name, ', '.join(val.split('|')))
|
||||||
|
elif datatype == 'series':
|
||||||
|
book[key] = concat(name, '%s [%s]'%(val,
|
||||||
|
fmt_sidx(record[CFM.cc_series_index_column_for(key)])))
|
||||||
|
elif datatype == 'datetime':
|
||||||
|
book[key] = concat(name,
|
||||||
|
format_date(val, CFM[key]['display'].get('date_format','dd MMM yyyy')))
|
||||||
|
elif datatype == 'bool':
|
||||||
|
if val:
|
||||||
|
book[key] = concat(name, __builtin__._('Yes'))
|
||||||
|
else:
|
||||||
|
book[key] = concat(name, __builtin__._('No'))
|
||||||
|
else:
|
||||||
|
book[key] = concat(name, val)
|
||||||
|
|
||||||
updated = self.db.last_modified()
|
updated = self.db.last_modified()
|
||||||
|
|
||||||
cherrypy.response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
cherrypy.response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
||||||
@ -218,7 +253,7 @@ class MobileServer(object):
|
|||||||
url_base = "/mobile?search=" + search+";order="+order+";sort="+sort+";num="+str(num)
|
url_base = "/mobile?search=" + search+";order="+order+";sort="+sort+";num="+str(num)
|
||||||
|
|
||||||
return html.tostring(build_index(books, num, search, sort, order,
|
return html.tostring(build_index(books, num, search, sort, order,
|
||||||
start, len(ids), url_base),
|
start, len(ids), url_base, CKEYS),
|
||||||
encoding='utf-8', include_meta_content_type=True,
|
encoding='utf-8', include_meta_content_type=True,
|
||||||
pretty_print=True)
|
pretty_print=True)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from calibre.library.server.utils import strftime
|
|||||||
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
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
|
from calibre.utils.date import format_date
|
||||||
|
|
||||||
E = ElementMaker()
|
E = ElementMaker()
|
||||||
|
|
||||||
@ -86,6 +87,39 @@ class XMLServer(object):
|
|||||||
kwargs[x] = serialize(y) if y else ''
|
kwargs[x] = serialize(y) if y else ''
|
||||||
|
|
||||||
c = kwargs.pop('comments')
|
c = kwargs.pop('comments')
|
||||||
|
|
||||||
|
CFM = self.db.field_metadata
|
||||||
|
CKEYS = [key for key in sorted(CFM.get_custom_fields(),
|
||||||
|
cmp=lambda x,y: cmp(CFM[x]['name'].lower(),
|
||||||
|
CFM[y]['name'].lower()))]
|
||||||
|
custcols = []
|
||||||
|
for key in CKEYS:
|
||||||
|
def concat(name, val):
|
||||||
|
return '%s:#:%s'%(name, unicode(val))
|
||||||
|
val = record[CFM[key]['rec_index']]
|
||||||
|
if val:
|
||||||
|
datatype = CFM[key]['datatype']
|
||||||
|
if datatype in ['comments']:
|
||||||
|
continue
|
||||||
|
k = str('CF_'+key[1:])
|
||||||
|
name = CFM[key]['name']
|
||||||
|
custcols.append(k)
|
||||||
|
if datatype == 'text' and CFM[key]['is_multiple']:
|
||||||
|
kwargs[k] = concat(name, ', '.join(val.split('|')))
|
||||||
|
elif datatype == 'series':
|
||||||
|
kwargs[k] = concat(name, '%s [%s]'%(val,
|
||||||
|
fmt_sidx(record[CFM.cc_series_index_column_for(key)])))
|
||||||
|
elif datatype == 'datetime':
|
||||||
|
kwargs[k] = concat(name,
|
||||||
|
format_date(val, CFM[key]['display'].get('date_format','dd MMM yyyy')))
|
||||||
|
elif datatype == 'bool':
|
||||||
|
if val:
|
||||||
|
kwargs[k] = concat(name, __builtin__._('Yes'))
|
||||||
|
else:
|
||||||
|
kwargs[k] = concat(name, __builtin__._('No'))
|
||||||
|
else:
|
||||||
|
kwargs[k] = concat(name, val)
|
||||||
|
kwargs['custcols'] = ','.join(custcols)
|
||||||
books.append(E.book(c, **kwargs))
|
books.append(E.book(c, **kwargs))
|
||||||
|
|
||||||
updated = self.db.last_modified()
|
updated = self.db.last_modified()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user