$def with (get_results)
$ q = query_param('q', '')
$ results_per_page = 100
$ page = query_param('page')
$if page:
$ page = int(page)
$else:
$ page = 1
$ offset = (page - 1) * results_per_page
$var title: Search Open Library for "$q"
$ results = get_results(q, offset=offset, limit=results_per_page)
$if q and 'error' in results:
$for line in results['error'].splitlines():
$line
$if not loop.last:
$if q and 'error' not in results:
$ response = results['response']
$ num_found = int(response['numFound'])
$if num_found:
$ungettext('1 hit', '%(count)s hits', response['numFound'], count=commify(response['numFound']))
$if num_found >= 2 and ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin()):
$ keys = '&'.join('key=%s' % doc['key'] for doc in response['docs'])
$else:
$_('No hits')
$for doc in response['docs']:
$ n = doc['name']
$ num = doc['work_count']
$ wc = ungettext("1 book", "%(count)d books", num, count=num)
$ date = ''
$if 'birth_date' in doc or 'death_date' in doc:
$ date = doc.get('birth_date', '') + ' - ' + doc.get('death_date', '')
$elif 'date' in doc:
$ date = doc['date']
-
$n $date
$wc
$if 'top_subjects' in doc:
$_('about %(subjects)s', subjects=', '.join(doc['top_subjects'])),
$:_('including %(topwork)s', topwork=doc.get('top_work', ''))
$:macros.Pager(page, num_found, results_per_page)