[IMP] pager

bzr revid: xmo@openerp.com-20130821140431-xwh2pk6xe880nz1q
This commit is contained in:
Xavier Morel 2013-08-21 16:04:31 +02:00
parent 7423dd5949
commit 93da6f2396
1 changed files with 16 additions and 15 deletions

View File

@ -91,19 +91,16 @@ class website(osv.osv):
def pager(self, url, total, page=1, step=30, scope=5, url_args=None): def pager(self, url, total, page=1, step=30, scope=5, url_args=None):
# Compute Pager # Compute Pager
d = {} page_count = int(math.ceil(float(total) / step))
d["page_count"] = int(math.ceil(float(total) / step))
page = max(1, min(int(page), d["page_count"])) page = max(1, min(int(page), page_count))
d["offset"] = (page-1) * step
scope -= 1 scope -= 1
pmin = max(page - int(math.floor(scope/2)), 1) pmin = max(page - int(math.floor(scope/2)), 1)
pmax = min(pmin + scope, d["page_count"]) pmax = min(pmin + scope, page_count)
if pmax - pmin < scope: if pmax - pmin < scope:
pmin = pmax - scope > 0 and pmax - scope or 1 pmin = pmax - scope if pmax - scope > 0 else 1
def get_url(page): def get_url(page):
_url = "%spage/%s/" % (url, page) _url = "%spage/%s/" % (url, page)
@ -111,14 +108,18 @@ class website(osv.osv):
_url = "%s?%s" % (_url, urllib.urlencode(url_args)) _url = "%s?%s" % (_url, urllib.urlencode(url_args))
return _url return _url
d["page"] = {'url': get_url(page), 'num': page} return {
d["page_start"] = {'url': get_url(pmin), 'num': pmin} "page_count": page_count,
d["page_end"] = {'url': get_url(min(pmax, page+1)), 'num': min(pmax, page+1)} "offset": (page - 1) * step,
d["pages"] = [] "page": {'url': get_url(page), 'num': page},
for page in range(pmin, pmax+1): "page_start": {'url': get_url(pmin), 'num': pmin},
d["pages"].append({'url': get_url(page), 'num': page}) "page_end": {'url': get_url(min(pmax, page + 1)),
'num': min(pmax, page + 1)},
return d "pages": [
{'url': get_url(page), 'num': page}
for page in xrange(pmin, pmax+1)
]
}
def list_pages(self, cr, uid, context=None): def list_pages(self, cr, uid, context=None):
""" Available pages in the website/CMS. This is mostly used for links """ Available pages in the website/CMS. This is mostly used for links