The next step is to add a method to the web.responder.html.Html class that accepts the output produced by fetchPaginatedByCustKey() and returns HTML. We also need to accept the current page number and a base URL to create links to the previous and next pages. Note that if the previous page number drops below 0, we simply reset it to 0.
The method might appear as follows:
# web.responder.html.Html
def buildPurchaseHistory(self, purchHist, pageNum, baseUrl) :
import locale
nextPage = pageNum + 1
prevPage = pageNum - 1
if prevPage < 0 : prevPage = 0
We do not define an upper limit for the pagination in this illustration, so the link for the next page might go past the end of the query result. In our example, in this case, a page with no results is displayed. If an upper limit is needed, create a domain service method that returns the value of pymongo.collection.count_documents(). You could then multiply the...