Mercurial > hg > ltpdarepo
changeset 19:76e6b6c5d5cb
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.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Mon, 27 Jun 2011 14:08:38 +0200 |
parents | 4c08f51482a3 |
children | d19c5ae165de |
files | src/ltpdarepo/pagination.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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