Click here to skip to this page's main content. Site Index

 Hello!   The State of California is participating in our In-Library lending program. Browse the growing lending library of over 200,000 eBooks!

Macro to display search results

This doc was last edited by Anand Chitipothu December 12, 2009.

plugin upstream
Templates in the website are disabled now. Editing them will not have any effect on the live website.
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
$def with (results, fulltext=False)

$ _ = i18n.get_namespace('/search')

<div style="margin-left: 30px; margin-right: 30px;">
<table border="0" cellpadding="10" cellspacing="0" width="100%">

$for b in results:
    $if fulltext:
        $ book = b[0]
        $ ocaid = b[1]
        $ pages = b[2]
    $else:
        $ book = b
        $ ocaid = None
    <tr>
    <td style="padding-left: 0px; padding-right: 0px; text-align: center; vertical-align: top; border-bottom: 1px solid #ccc;">
        $ olid = book.key.split('/')[-1]
        <a href="$book.key"><img src="http://covers.openlibrary.org/b/olid/$olid-S.jpg?default=http://openlibrary.org/static/images/blank.book.png" height="60" /></a>
    </td>
    <td valign="middle" width="100%" style="padding-left: 10px; border-bottom: 1px solid #ccc;">
        <a href="$book.key/$book.title.replace(' ', '_').replace('/', '_')" class="result">$book.title_prefix $book.title</a>
        $if book.get('authors', None):
            <span class="result-small">$_.by
            $ authorlist = ', '.join([thingrepr(author).rstrip() for author in book.authors])
            $:authorlist
            </span>
        $if book.ocaid: &nbsp;&nbsp;<a href="http://www.archive.org/stream/$book.ocaid" class="ReadNow">$_.fulltext</a>
        <div class="result-small">
            $if book.publishers:
                $(', '.join(book.publishers)), $book.publish_date
            $else:
                $book.publish_date
            $book.physical_format
        </div>
        $if fulltext:
            <p>Pages:
            $if len(pages)==0: <i>Unknown</i>
            $ a = []
            $for pn, pg in pages:
                $ a.append('<a href="http://www.archive.org/stream/%s#page/n%s/mode/1up">%s</a>'% (book.ocaid, pn-1, pg))
            $:(',&nbsp;&nbsp;'.join(a))
            </p>
    </td></tr>
</table>
</div>