$def with (now, total, shoal, page, pages, size)
<div class="row-fluid">
    <div class="span6 offset3" style="text-align:center">
        <h2>List of Active Squids</h2>
        $if total > 0:
            <h5 class="text-success">$total active in the last $squid_active_time seconds</h5>
        $else:
            <h5 class="text-info">None active in the last $squid_active_time seconds</h5>
        </div>
<div class="row-fluid">
  <div class='span12'>
    <table class="table table-condensed table-hover">
      <thead>
        <tr>
          <th>#</th>
          <th>Public IP</th>
          <th class="hidden-phone">Private IP</th>
          <th>Bytes Out</th>
          <th>City</th>
          <th>Region</th>
          <th class="hidden-phone">Country</th>
          <th class="hidden-phone">Latitude</th>
          <th class="hidden-phone">Longitude</th>
          <th class="hidden-phone">Last Received</th>
          <th>Alive</th>
        </tr>
      </thead>
      <tbody>
        $for i,squid in enumerate(shoal):
            $ last_msg = int(now - squid.last_active)
            $ alive_time = int(now - squid.created); 
            $ hour = int(alive_time/60/60)
            $ minute = (alive_time - hour*60*60) / 60
            $ second = alive_time - hour*60*60 - minute*60
    
            $if last_msg < squid_active_time/3:
                $ state = 'success'
            $elif last_msg >= squid_active_time/3 and last_msg < squid_active_time*2/3:
                $ state = 'warning'
            $else:
                $ state = 'error'
    
            <tr class='$state'>
                <td><span class="badge badge-$state">$((i+1)+(page-1)*size)</td>
                <td>$squid.public_ip</td>
                <td class="hidden-phone">$squid.private_ip</td>
                <td>$squid.load kB/s</td>
                <td>$squid.geo_data['city']</td>
                <td>$squid.geo_data['region_name']</td>
                <td class="hidden-phone">$squid.geo_data['country_name']</td>
                <td class="hidden-phone">$squid.geo_data['latitude']</td>
                <td class="hidden-phone">$squid.geo_data['longitude']</td>
                <td class="hidden-phone">$(last_msg)s</td>
                <td>$(hour)h$(minute)m$(second)s</td>
            </tr>
      </tbody>
    </table>
  </div>
</div>
$if size != 0 and pages > 1:
  <div class="row-fluid">
    <div class"span1">
      <a href="/0">Show All</a>
    </div>
  </div>
$if pages > 1:
  <div class="row-fluid"
    <div class="span12">
      <div class="pagination pagination-centered">
        <ul>
        $if page == 1:
          <li class="disabled"><a href="#">&laquo;</a></li>
          <li class="disabled"><a href="#">&lsaquo;</a></li>
        $else:
          <li><a href="?page=1">&laquo;</a></li>
          <li><a href="?page=$(page-1)">&lsaquo;</a></li>
        $if pages < 10:
          $for p in range(pages):
            $if p+1 == page:
              <li class="active"><a href="#">$(p+1)</a></li>
            $else:
              <li><a href="?page=$(p+1)">$(p+1)</a></li>
        $else:
          $ lower = 0
          $ upper = page + 3
          $if page > 5 and page <= pages:
            $ lower = page - 4 
            $ upper = page + 3
          $if page > pages - 5 and page <= pages:
            $ lower = page - 4
            $ upper = pages
          $for p in range(lower,upper):
            $if p+1 == page:
              <li class="active"><a href="#">$(p+1)</a></li>
            $else:
              <li><a href="?page=$(p+1)">$(p+1)</a></li>
          $if page < (pages - 5):
            <li><span>...</span></li>
            $for p in range(pages-2,pages):
              <li><a href="?page=$(p+1)">$(p+1)</a></li>
        $if page == pages:
          <li class="disabled"><a href="#">&rsaquo;</a></li>
          <li class="disabled"><a href="#">&raquo;</a></li>
        $else:
          <li><a href="?page=$(page+1)">&rsaquo;</a></li>
          <li><a href="?page=$pages">&raquo;</a></li>
        </ul>
      </div>
    </div>
  </div>
