# $Id$ # $URL$ websiteConfig = configs['website'] # FIXME: Move to config! NR_OF_PAGES=5 RESULTS_PER_PAGE=10 def _paginatorLink(pageNumber, text, arguments): offset = (pageNumber-1) * RESULTS_PER_PAGE 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 = 'en' # path.startswith('/en/') and 'en' or 'nl' websiteConfig.setDefaults(section='paginate',language=language) next = websiteConfig.get('next',default='next') prev = websiteConfig.get('previous',default='previous') if nrOfResults > RESULTS_PER_PAGE: yield """