autocat3/BibrecPage.py

112 lines
3.3 KiB
Python
Raw Permalink Normal View History

2019-03-28 13:45:03 +00:00
#!/usr/bin/env python
# -*- mode: python; indent-tabs-mode: nil; -*- coding: utf-8 -*-
"""
BibrecPage.py
Copyright 2009-2010 by Marcello Perathoner
Distributable under the GNU General Public License Version 3 or newer.
The bibrec page.
"""
from __future__ import unicode_literals
import cherrypy
from libgutenberg import GutenbergGlobals as gg
2019-07-26 15:54:24 +00:00
from i18n_tool import ugettext as _
from i18n_tool import ungettext as __
2019-03-28 13:45:03 +00:00
import BaseSearcher
import Page
class BibrecPage (Page.Page):
""" Implements the bibrec page. """
def index (self, **dummy_kwargs):
""" A bibrec page. """
os = BaseSearcher.OpenSearch ()
os.log_request ('bibrec')
dc = BaseSearcher.DC (cherrypy.engine.pool)
# the bulk of the work is done here
dc.load_from_database (os.id)
if not dc.files:
# NOTE: Error message
raise cherrypy.HTTPError (404, _('No ebook by that number.'))
# add these fields so we won't have to test for their existence later
dc.extra_info = None
dc.url = None
dc.translate ()
dc.header = gg.cut_at_newline (dc.title)
os.title = dc.make_pretty_title ()
dc.extra_info = ''
dc.class_ = BaseSearcher.ClassAttr ()
dc.order = 10
dc.icon = 'book'
if 'Sound' in dc.categories:
dc.icon = 'audiobook'
os.title_icon = dc.icon
os.twit = os.title
os.qrcode_url = '/cache/epub/%d/pg%d.qrcode.png' % (os.id, os.id)
2019-03-28 13:45:03 +00:00
os.entries.append (dc)
s = cherrypy.session
last_visited = s.get ('last_visited', [])
last_visited.append (os.id)
s['last_visited'] = last_visited
# can we find some meaningful breadcrumbs ?
for a in dc.authors:
if a.marcrel in ('aut', 'cre'):
book_cnt = BaseSearcher.sql_get (
"select count (*) from mn_books_authors where fk_authors = %(aid)s", aid = a.id)
if book_cnt > 1:
os.breadcrumbs.append ((
__('One by {author}', '{count} by {author}', book_cnt).format (
count = book_cnt, author = dc.make_pretty_name (a.name)),
_('Find more ebooks by the same author.'),
os.url ('author', id = a.id)
))
2020-09-03 18:04:42 +00:00
if os.format == 'html':
2019-03-28 13:45:03 +00:00
cat = BaseSearcher.Cat ()
cat.header = _('Similar Books')
cat.title = _('Readers also downloaded…')
cat.rel = 'related'
cat.url = os.url ('also', id = os.id)
cat.class_ += 'navlink grayed noprint'
cat.icon = 'suggestion'
cat.order = 30
os.entries.append (cat)
for bookshelf in dc.bookshelves:
cat = BaseSearcher.Cat ()
cat.title = _('In {bookshelf}').format (bookshelf = bookshelf.bookshelf)
cat.rel = 'related'
cat.url = os.url ('bookshelf', id = bookshelf.id)
cat.class_ += 'navlink grayed'
cat.icon = 'bookshelf'
cat.order = 33
os.entries.append (cat)
os.total_results = 1
2020-09-03 18:04:42 +00:00
os.template = 'bibrec'
2019-03-28 13:45:03 +00:00
os.page = 'bibrec'
os.og_type = 'book'
os.finalize ()
return self.format (os)