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