NR_OF_PAGES=10 RESULTS_PER_PAGE=10 def _paginatorLink(pageNumber, text, arguments): offset = (pageNumber-1) * 10 linkArguments = arguments.copy() linkArguments['offset'] = offset encodedArguments = escapeHtml(urlencode(linkArguments)).replace('"', '"') yield """%(text)s """ % {'args': encodedArguments, 'text': text} def paginate(offset, nrOfResults, resultsPerPage=RESULTS_PER_PAGE, nrOfPages=NR_OF_PAGES): currentPage = offset / resultsPerPage + 1 firstPage = max(1, currentPage - nrOfPages) lastPage = min(currentPage + nrOfPages, int(ceil(nrOfResults / float(resultsPerPage)))) return range(firstPage, currentPage), currentPage, range(currentPage+1, lastPage+1) def main(offset, nrOfResults, headers={}, arguments={}, path='', *args, **kwargs): language = path.startswith('/en/') and 'en' or 'nl' if nrOfResults > RESULTS_PER_PAGE: yield """
\n""" firstPages, currentPage, lastPages = paginate(offset, nrOfResults) if firstPages: yield _paginatorLink(currentPage-1, {'nl':'Vorige', 'en':'Previous'}[language], arguments) for pageNumber in firstPages: yield _paginatorLink(pageNumber, pageNumber, arguments) yield """%s """ % currentPage for pageNumber in lastPages: yield _paginatorLink(pageNumber, pageNumber, arguments) if lastPages: yield _paginatorLink(currentPage+1, {'nl':'Volgende', 'en':'Next'}[language], arguments) yield """
\n"""