Merge from trunk plus filter custom fields.

This commit is contained in:
Charles Haley 2010-10-16 14:44:38 +01:00
commit 468754e7ab
3 changed files with 12 additions and 3 deletions

View File

@ -17,6 +17,7 @@ from calibre.utils.ordered_dict import OrderedDict
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.utils.config import prefs from calibre.utils.config import prefs
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
def render_book_list(ids, suffix=''): # {{{ def render_book_list(ids, suffix=''): # {{{
pages = [] pages = []
@ -495,7 +496,7 @@ class BrowseServer(object):
other_fmts = [x for x in fmts if x.lower() != fmt.lower()] other_fmts = [x for x in fmts if x.lower() != fmt.lower()]
if other_fmts: if other_fmts:
ofmts = [u'<a href="/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'\ ofmts = [u'<a href="/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'\
.format(fmt, fname, id_, fmt.upper()) for fmt in .format(f, fname, id_, f.upper()) for f in
other_fmts] other_fmts]
ofmts = ', '.join(ofmts) ofmts = ', '.join(ofmts)
args['other_formats'] = u'<strong>%s: </strong>' % \ args['other_formats'] = u'<strong>%s: </strong>' % \
@ -545,8 +546,11 @@ class BrowseServer(object):
ofmts = ', '.join(ofmts) ofmts = ', '.join(ofmts)
args['formats'] = ofmts args['formats'] = ofmts
fields, comments = [], [] fields, comments = [], []
displayed_custom_fields = custom_fields_to_display(self.db)
for field, m in list(mi.get_all_standard_metadata(False).items()) + \ for field, m in list(mi.get_all_standard_metadata(False).items()) + \
list(mi.get_all_user_metadata(False).items()): list(mi.get_all_user_metadata(False).items()):
if m['is_custom'] and field not in displayed_custom_fields:
continue
if m['datatype'] == 'comments' or field == 'comments': if m['datatype'] == 'comments' or field == 'comments':
comments.append((m['name'], comments_to_html(mi.get(field, comments.append((m['name'], comments_to_html(mi.get(field,
'')))) ''))))

View File

@ -140,7 +140,7 @@ class ContentServer(object):
updated = self.build_time updated = self.build_time
else: else:
with cover as f: with cover as f:
updated = fromtimestamp(os.stat(f.name).st_mtime) updated = fromtimestamp(os.fstat(f.fileno()).st_mtime)
cover = f.read() cover = f.read()
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated) cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)

View File

@ -120,7 +120,8 @@ if not _run_once:
object.__setattr__(self, 'name', name) object.__setattr__(self, 'name', name)
def __getattribute__(self, attr): def __getattribute__(self, attr):
if attr == 'name': if attr in ('name', '__enter__', '__str__', '__unicode__',
'__repr__'):
return object.__getattribute__(self, attr) return object.__getattribute__(self, attr)
fobject = object.__getattribute__(self, 'fobject') fobject = object.__getattribute__(self, 'fobject')
return getattr(fobject, attr) return getattr(fobject, attr)
@ -141,6 +142,10 @@ if not _run_once:
def __unicode__(self): def __unicode__(self):
return repr(self).decode('utf-8') return repr(self).decode('utf-8')
def __enter__(self):
fobject = object.__getattribute__(self, 'fobject')
fobject.__enter__()
return self
m = mode[0] m = mode[0]
random = len(mode) > 1 and mode[1] == '+' random = len(mode) > 1 and mode[1] == '+'