<meta xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude" py:strip="">
	<?python
	from pylons import request
	def get_page_href(page, arg='page', kwargs=None):
		if not kwargs:
			kwargs = dict()
		kwargs[arg] = str(page)
		return tg.url(request.path, params=kwargs)
	?>
	<span py:def="display_page_link(paginator, page, arg='page', kwargs=None)">
        <a py:if="page != paginator.page"
           py:attrs="dict(href=get_page_href(page, arg=arg, kwargs=kwargs))" py:content="page"></a>
    <span class="current" py:if="page == paginator.page" py:content="page"></span>
    </span>

    <p py:def="paginate_nav(paginator, arg='page', kwargs=None)" class="pagination">
        <span class="disabled" py:if="paginator.page_count > 3 and not paginator.page > 1">◄</span>
        <a py:if="paginator.page_count > 3 and paginator.page > 1"
		   py:attrs="dict(href=get_page_href(paginator.page-1, arg=arg, kwargs=kwargs))">◄</a>
		<span py:if="paginator.page_count &lt; 6" py:for="page in range(1, paginator.page_count+1)">
            ${display_page_link(paginator, page, arg=arg, kwargs=kwargs)}
        </span>
        <span py:if="paginator.page_count >= 6"  py:with="pages=range(1, paginator.page_count+1)">
            <span py:if="paginator.page &lt; 4">
                <span py:if="paginator.page &lt; 3" py:for="page in pages[:3]">
                    ${display_page_link(paginator, page, arg=arg, kwargs=kwargs)}
                </span>
                <span py:if="paginator.page >= 3" py:for="page in pages[:paginator.page+1]">
                    ${display_page_link(paginator, page, arg=arg, kwargs=kwargs)}
                </span>
                ...
                ${display_page_link(paginator, paginator.page_count, arg=arg, kwargs=kwargs)}
            </span>
            <span py:if="paginator.page >= 4 and paginator.page &lt;= (paginator.page_count - 3)">
                ${display_page_link(paginator, 1, arg=arg, kwargs=kwargs)}
                ...
                <span py:for="page in pages[paginator.page-3:paginator.page+2]">
                    ${display_page_link(paginator, page, arg=arg, kwargs=kwargs)}
                </span>
                ...
                ${display_page_link(paginator, paginator.page_count, arg=arg, kwargs=kwargs)}
            </span>
            <span py:if="paginator.page > (paginator.page_count - 3)">
                ${display_page_link(paginator, 1, arg=arg, kwargs=kwargs)}
                ...
                <span py:for="page in pages[-4:]">
                    ${display_page_link(paginator, page, arg=arg, kwargs=kwargs)}
                </span>
            </span>
        </span>
        <span class="disabled"
		py:if="paginator.page_count > 3 and not paginator.page &lt; paginator.page_count">►</span>
        <a py:if="paginator.page_count > 3 and paginator.page &lt; paginator.page_count"
		   py:attrs="dict(href=get_page_href(paginator.page+1, arg=arg, kwargs=kwargs))">►</a>
    </p>
</meta>