# HG changeset patch # User Daniele Nicolodi # Date 1309176518 -7200 # Node ID 76e6b6c5d5cb76f3e4d0b8b72689fba07cdce269 # Parent 4c08f51482a352ab44e9cd539c55c35763dcf92d Add a 'limits' property to the Pagination class. The 'limits' property returns the index boundaries for the current page in the paginated list and is usefull to implement SQL queries. diff -r 4c08f51482a3 -r 76e6b6c5d5cb src/ltpdarepo/pagination.py --- a/src/ltpdarepo/pagination.py Mon Jun 27 14:08:38 2011 +0200 +++ b/src/ltpdarepo/pagination.py Mon Jun 27 14:08:38 2011 +0200 @@ -1,10 +1,10 @@ from math import ceil, floor class Pagination(object): - def __init__(self, current, bsize, total, items=9): + def __init__(self, current, size, count, items=9): self.current = current - self.bsize = bsize - self.total = total + self.size = size + self.count = count self.items = items @property @@ -13,7 +13,7 @@ @property def pages(self): - return int(ceil(self.total / float(self.bsize))) + return int(ceil(self.count / float(self.size))) @property def has_prev(self): @@ -23,6 +23,10 @@ def has_next(self): return self.current < self.pages + @property + def limits(self): + return ((self.current - 1) * self.size, self.size) + def __iter__(self): # cache number of pages npages = self.pages