Sunday, June 6, 2010

PageLinks - a simple helper class for PagedQuery

On May 26th I added PageLinks to the already published PagedQuery class available on he3-appengine-lib. PagedQuery is a python class to add a paging abstraction to the vanilla db.Query and db.GqlQuery used on Google App Engine (announced here). PageLinks is a simple helper class that generates a sequence of page number / URL pairs for use in page navigation, including previous and next links.

Usage of PageLinks is straight forward. Create and initialise an instance of the class and then call the get_links() method:

pageLinks = he3.db.tower.paging.PageLinks( page=2,
   page_count=3,  url_root='http://myresources/', page_field='page')
Sequence_of_links = pageLinks.get_links()

Sequence_of_links now equals:

[('prev', 'http://myresources/?page=1'),
('1', 'http://myresources/?page=1'),
('2', 'http://myresources/?page=1'),
('3', 'http://myresources/?page=2'),
('next',  'http://myresources/?page=3')]

This is simple helper class. I think I am most proud of the fact I finally made good use of a Python List Comprehension.

1 comment:

  1. I have been using this replica watch, Replica Audemars Piguet Watchesit is a very beautiful and affordable automatic watch, good size, great quality, elegant and temperament, is my favorite style. Replica Audemars Piguet royal oak offshoreI shared this website with my friends and they were very happy.