Implement #3235 (patch to add an author menu when sorting stanza catalogue by author)

This commit is contained in:
Kovid Goyal 2009-08-21 13:49:08 -06:00
parent 50d66d6f3a
commit 69a9eddfea
2 changed files with 37 additions and 6 deletions

View File

@ -105,6 +105,15 @@ class LibraryServer(object):
</entry>
'''))
STANZA_AUTHOR_ENTRY=MarkupTemplate(textwrap.dedent('''\
<entry xmlns:py="http://genshi.edgewall.org/">
<title>${authors}</title>
<id>urn:calibre:${record[FM['id']]}</id>
<updated>${timestamp}</updated>
<link type="application/atom+xml" href="/?authorid=${record[FM['id']]}" />
</entry>
'''))
STANZA = MarkupTemplate(textwrap.dedent('''\
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:py="http://genshi.edgewall.org/">
@ -330,24 +339,30 @@ class LibraryServer(object):
@expose
def stanza(self, search=None, sortby=None):
def stanza(self, search=None, sortby=None, authorid=None):
'Feeds to read calibre books on a ipod with stanza.'
books = []
updated = self.db.last_modified()
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
cherrypy.response.headers['Content-Type'] = 'text/xml'
if not sortby and not search:
if not sortby and not search and not authorid:
return self.STANZA_MAIN.generate(subtitle='', data=books, FM=FIELD_MAP,
updated=updated, id='urn:calibre:main').render('xml')
if authorid:
authorid=int(authorid)
au = self.db.authors(authorid, index_is_id=True)
ids = self.db.data.get_matches('authors', au)
else:
ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set()
record_list = list(iter(self.db))
if sortby == "byauthor":
record_list.sort(lambda x, y: cmp(x[FIELD_MAP['author_sort']], y[FIELD_MAP['author_sort']]))
elif sortby == "bytitle":
elif sortby == "bytitle" or authorid:
record_list.sort(lambda x, y: cmp(title_sort(x[FIELD_MAP['title']]),
title_sort(y[FIELD_MAP['title']])))
else:
record_list = reversed(record_list)
author_list=[]
for record in record_list:
if record[0] not in ids: continue
r = record[FIELD_MAP['formats']]
@ -374,6 +389,19 @@ class LibraryServer(object):
fmt_sidx(float(record[FIELD_MAP['series_index']]))))
fmt = 'epub' if 'EPUB' in r else 'pdb'
mimetype = guess_type('dummy.'+fmt)[0]
if sortby == "byauthor":
if authors and authors not in author_list:
author_list.append(authors)
books.append(self.STANZA_AUTHOR_ENTRY.generate(
authors=authors,
record=record, FM=FIELD_MAP,
port=self.opts.port,
extra=''.join(extra),
mimetype=mimetype,
fmt=fmt,
timestamp=strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5]),
).render('xml').decode('utf8'))
else:
books.append(self.STANZA_ENTRY.generate(
authors=authors,
record=record, FM=FIELD_MAP,
@ -434,7 +462,7 @@ class LibraryServer(object):
'The / URL'
want_opds = cherrypy.request.headers.get('Stanza-Device-Name', 919) != \
919 or cherrypy.request.headers.get('Want-OPDS-Catalog', 919) != 919
return self.stanza(search=kwargs.get('search', None), sortby=kwargs.get('sortby',None)) if want_opds else self.static('index.html')
return self.stanza(search=kwargs.get('search', None), sortby=kwargs.get('sortby',None), authorid=kwargs.get('authorid',None)) if want_opds else self.static('index.html')
@expose

3
todo
View File

@ -6,3 +6,6 @@
* Add a languages column to books. Best implementation is comma separated IANA codes
* Add a hash column to the formats table (used for stanza identifier)
* Fix blockquote handling in sphinx templates
* Fix ebook-viewer going to links