/upstream/templates/search/authors.tmpl
Type: /type/template
body: value: $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"

<div id="contentHead">
    $if q:
        $ results = get_results(q, offset=offset, limit=results_per_page)
        $if 'error' not in results:
            $ response = results['response']
            $ num_found = int(response['numFound'])
            $if num_found >= 2 and "merge-authors" in ctx.features and ctx.user:
                $ keys = '&'.join('key=%s' % doc['key'] for doc in response['docs'])
                <div class="mergeThis">
                    <p class="smaller brown sansserif collapse">Is the same author listed twice?</p>
                    <a class="large sansserif" href="/authors/merge?$keys">Merge authors</a>
                </div>
    <h1>
        $_("Author Search")
    </h1>

    $if q and 'error' not in results:
        $if num_found:
            <p class="sansserif darkgreen collapse"><strong>$commify(response['numFound']) hit$("s" if response['numFound'] != 1 else "")</strong></p>
        $else:
            <p class="sansserif red collapse"><strong>No hits</strong></span></p>
</div>

<div id="contentMeta">

    <div class="section">

    <form class="siteSearch olform" action="">
        <input type="text" class="larger" name="q" size="100" style="width: 505px;" value="$q"/>
        <input type="submit"  class="large" value="$_('Search')"/>
    </form>

    </div>

    $if q and 'error' in results:
        <strong>
            $for line in results['error'].splitlines():
                $line
                $if not loop.last:
                    <br>
        </strong>

    $if q and 'error' not in results:
        <ul class="authorList">
        $for doc in response['docs']:
            $ n = doc['name']
            $ num = doc['work_count']
            $ wc = "1 book" if num == 1 else commify(num) + " books"
            $ 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']
            <li class="sansserif">
            <a href="/authors/$doc['key']" class="larger">$n</a>&nbsp;<span class="brown small">$date</span><br />
            <span class="small grey"><b>$wc</b>  
            $if 'top_subjects' in doc:
                about $', '.join(doc['top_subjects']), 
            including <i>$doc.get('top_work', '')</i></span>
            </li>
        </ul>

        $:macros.Pager(page, num_found, results_per_page)
</div>
plugin: worksearch
m: edit