def index(self, **dummy_kwargs): """ Output the start page. """ os = BaseSearcher.OpenSearch() os.log_request('start') os.search_terms = '' os.title = { 'mobile': _('PG Mobile'), 'opds': _('Project Gutenberg'), 'stanza': _('Project Gutenberg') }.get(os.format, _('Search Project Gutenberg')) cat = BaseSearcher.Cat() cat.header = _( 'Welcome to Project Gutenberg. Use the search box to find your book or pick a link.' ) cat.title = _('Popular') cat.subtitle = _('Our most popular books.') cat.url = os.url('search', sort_order='downloads') cat.class_ += 'navlink' cat.icon = 'popular' cat.order = 2 os.entries.append(cat) cat = BaseSearcher.Cat() cat.title = _('Latest') cat.subtitle = _('Our latest releases.') cat.url = os.url('search', sort_order='release_date') cat.class_ += 'navlink' cat.icon = 'date' cat.order = 3 os.entries.append(cat) cat = BaseSearcher.Cat() cat.title = _('Random') cat.subtitle = _('Random books.') cat.url = os.url('search', sort_order='random') cat.class_ += 'navlink' cat.icon = 'random' cat.order = 4 os.entries.append(cat) os.total_results = 0 os.template = 'results' os.page = 'start' os.url_share = os.url('/', host=os.file_host) os.twit = os.tagline os.finalize() return self.format(os)
def fix_dc(self, dc, os): """ Add some info to dc for easier templating. Also make sure that dc `walks like a cat´. """ super(MobileFormatter, self).fix_dc(dc, os) for file_ in dc.files + dc.generated_files: if len(file_.mediatypes) == 1: type_ = six.text_type(file_.mediatypes[0]) m = type_.partition(';')[0] if m in MOBILE_TYPES: cat = BaseSearcher.Cat() cat.type = file_.mediatypes[0] cat.header = _('Download') cat.title = file_.hr_filetype cat.extra = file_.hr_extent cat.charset = file_.encoding cat.url = file_.url cat.icon = dc.icon cat.icon2 = 'download' cat.class_ += 'filelink' cat.order = 20 os.entries.append(cat)
def fixup (self, os): if (os.start_index == 1 and len (os.entries) > 0): # browse-by-author page for maintainers if 'is-catalog-maintainer' in cherrypy.request.cookie: cat = BaseSearcher.Cat () cat.type = mt.html cat.rel = 'related' cat.title = _('Browse by Author') cat.url = "/browse/authors/%s#a%d" % (os.author[:1].lower (), os.id) cat.class_ += 'navlink grayed' cat.icon = 'internal' cat.order = 9 os.entries.insert (0, cat) # wikipedia links etc. rows = BaseSearcher.SQLSearcher.execute ( """SELECT url, description AS title FROM author_urls WHERE fk_authors = %(fk_authors)s""", { 'fk_authors': os.id } ) for row in rows: cat = BaseSearcher.Cat () cat.type = mt.html cat.rel = 'related' cat.title = _('See also: {title}').format (title = row.title) cat.url = row.url cat.class_ += 'navlink grayed' cat.icon = 'external' cat.order = 8 os.entries.insert (0, cat) # author aliases if os.format == 'html': rows = BaseSearcher.SQLSearcher.execute ( """SELECT alias AS title FROM aliases WHERE fk_authors = %(fk_authors)s AND alias_heading = 1""", { 'fk_authors': os.id } ) for row in rows: cat = BaseSearcher.Cat () cat.title = _('Alias {alias}').format (alias = row.title) cat.class_ += 'grayed' cat.icon = 'alias' cat.order = 7 os.entries.insert (0, cat)
def did_you_mean(os, corr, corrected_query): """ Message. """ cat = BaseSearcher.Cat() cat.rel = '__didyoumean__' cat.title = _('Did you mean: {correction}').format(correction=corr) cat.url = os.url('search', query=corrected_query) cat.class_ += 'navlink' cat.icon = 'suggestion' cat.order = 12 return cat
def no_records_found(os): """ Message. """ cat = BaseSearcher.Cat() cat.rel = '__notfound__' cat.title = _('No records found.') cat.url = os.url('start') cat.class_ += 'navlink grayed' cat.icon = 'bibrec' cat.order = 11 return cat
def sort_by_release_date(os): """ Append the sort by release date link. """ cat = BaseSearcher.Cat() cat.rel = 'new' cat.title = _('Sort by Release Date') cat.url = os.url_carry(sort_order='release_date') cat.class_ += 'navlink grayed' cat.icon = 'date' cat.order = 4.3 os.entries.insert(0, cat)
def sort_by_quantity(os): """ Append the sort by quantity link. """ cat = BaseSearcher.Cat() cat.rel = 'numerous' cat.title = _('Sort by Quantity') cat.url = os.url_carry(sort_order='quantity') cat.class_ += 'navlink grayed' cat.icon = 'quantity' cat.order = 4.2 os.entries.insert(0, cat)
def sort_by_title(os): """ Append the sort alphabetically link. """ cat = BaseSearcher.Cat() cat.rel = 'alphabethical' cat.title = _('Sort Alphabetically') cat.url = os.url_carry(sort_order='title') cat.class_ += 'navlink grayed' cat.icon = 'alpha' cat.order = 4.1 os.entries.insert(0, cat)
def sort_by_downloads(os): """ Append the sort by downloads link. """ cat = BaseSearcher.Cat() cat.rel = 'popular' cat.title = _('Sort by Popularity') cat.url = os.url_carry(sort_order='downloads') cat.class_ += 'navlink grayed' cat.icon = 'popular' cat.order = 4.0 os.entries.insert(0, cat)
def status_line(os): """ Placeholder for status line. """ cat = BaseSearcher.Cat() cat.rel = '__statusline__' cat.class_ += 'grayed' cat.icon = 'bibrec' cat.order = 10 cat.header = os.title cat.title = _(u"Displaying results {from_}–{to}").format( from_=os.start_index, to=os.end_index) return cat
def fixup(self, os): """ strip marc subfields, add social media hints and facet links """ for e in os.entries: if '$' in e.title: e.title = DublinCore.strip_marc_subfields(e.title) if (os.sort_order == 'release_date' and os.total_results > 0 and os.start_index == 1): cat = BaseSearcher.Cat() cat.title = _('Follow new books on Twitter') cat.subtitle = _("Follow our new books on Twitter.") cat.url = 'https://twitter.com/gutenberg_new' cat.class_ += 'navlink grayed' cat.icon = 'twitter' cat.order = 5 os.entries.insert(0, cat) cat = BaseSearcher.Cat() cat.title = _('Follow new books on Facebook') cat.subtitle = _( "Follow the link and like the page to have us post new books to your wall." ) cat.url = 'https://www.facebook.com/gutenberg.new' cat.class_ += 'navlink grayed' cat.icon = 'facebook' cat.order = 5 os.entries.insert(0, cat) if (len(os.query) and os.start_index == 1): sql2 = BaseSearcher.SQLStatement() sql2.query = "select count (*) from bookshelves" sql2.fulltext('bookshelves.tsvec', os.query) rows = BaseSearcher.SQLSearcher.execute(*sql2.build()) if rows[0][0] > 0: cat = BaseSearcher.Cat() cat.rel = 'related' cat.title = _('Bookshelves') cat.subtitle = __('One bookshelf matches your query.', '{count} bookshelves match your search.', rows[0][0]).format(count=rows[0][0]) cat.url = os.url('bookshelf_search', query=os.query) cat.class_ += 'navlink grayed' cat.icon = 'bookshelf' cat.order = 3 os.entries.insert(0, cat) sql2 = BaseSearcher.SQLStatement() sql2.query = "select count (*) from subjects" sql2.fulltext('subjects.tsvec', os.query) rows = BaseSearcher.SQLSearcher.execute(*sql2.build()) if rows[0][0] > 0: cat = BaseSearcher.Cat() cat.rel = 'related' cat.title = _('Subjects') cat.subtitle = __( 'One subject heading matches your search.', '{count} subject headings match your search.', rows[0][0]).format(count=rows[0][0]) cat.url = os.url('subject_search', query=os.query) cat.class_ += 'navlink grayed' cat.icon = 'subject' cat.order = 3 os.entries.insert(0, cat) sql2 = BaseSearcher.SQLStatement() sql2.query = "select count (*) from authors" sql2.fulltext('authors.tsvec', os.query) rows = BaseSearcher.SQLSearcher.execute(*sql2.build()) if rows[0][0] > 0: cat = BaseSearcher.Cat() cat.rel = 'related' cat.title = _('Authors') cat.subtitle = __('One author name matches your search.', '{count} author names match your search.', rows[0][0]).format(count=rows[0][0]) cat.url = os.url('author_search', query=os.query) cat.class_ += 'navlink grayed' cat.icon = 'author' cat.order = 3 os.entries.insert(0, cat)
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 cherrypy.tools.rate_limiter.e404() 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 = '//%s/cache/epub/%d/pg%d.qrcode.png' % (os.file_host, os.id, os.id) 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))) if os.format in ('html', 'mobile'): 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) if os.format in ('mobile', ): for author in dc.authors: cat = BaseSearcher.Cat() cat.title = _('By {author}').format( author=author.name_and_dates) cat.rel = 'related' cat.url = os.url('author', id=author.id) cat.class_ += 'navlink grayed' cat.icon = 'author' cat.order = 31 os.entries.append(cat) for subject in dc.subjects: cat = BaseSearcher.Cat() cat.title = _('On {subject}').format(subject=subject.subject) cat.rel = 'related' cat.url = os.url('subject', id=subject.id) cat.class_ += 'navlink grayed' cat.icon = 'subject' cat.order = 32 os.entries.append(cat) os.total_results = 1 os.template = 'results' if os.format == 'mobile' else 'bibrec' os.page = 'bibrec' os.og_type = 'book' os.finalize() return self.format(os)