[FIX] website: pager must add url extra params in genarated urls

bzr revid: chm@openerp.com-20130814105400-it4s51b6wwdiipb1
This commit is contained in:
Christophe Matthieu 2013-08-14 12:54:00 +02:00
parent e16a75fdb6
commit f78d8e22e0
3 changed files with 14 additions and 8 deletions

View File

@ -70,7 +70,7 @@ class website(osv.osv):
}
return request.registry.get("ir.ui.view").render(request.cr, request.uid, template, values, context=context)
def pager(self, url, total, page=1, step=30, scope=5):
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))
@ -86,13 +86,18 @@ class website(osv.osv):
if pmax - pmin < scope:
pmin = pmax - scope > 0 and pmax - scope or 1
def get_url(page):
_url = "%spage/%s/" % (url, page)
if url_args:
_url = "%s?%s" % (_url, urllib.urlencode(url_args))
return _url
d["page"] = {'url': "%spage/%s/" % (url, page), 'num': page}
d["page_start"] = {'url': "%spage/%s/" % (url, pmin), 'num': pmin}
d["page_end"] = {'url': "%spage/%s/" % (url, min(pmax, page+1)), 'num': min(pmax, page+1)}
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': "%spage/%s/" % (url, page), 'num': page})
d["pages"].append({'url': get_url(page), 'num': page})
return d

View File

@ -61,9 +61,10 @@ class Ecommerce(http.Controller):
domain += [('website_published', '=', True)]
if post.get("search"):
domain += ['|', '|',
domain += ['|', '|', '|',
('name', 'ilike', "%%%s%%" % post.get("search")),
('description', 'ilike', "%%%s%%" % post.get("search")),
('description_website', 'ilike', "%%%s%%" % post.get("search")),
('pos_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))]
if cat_id:
cat_id = int(cat_id)
@ -71,7 +72,7 @@ class Ecommerce(http.Controller):
step = 20
product_count = len(product_obj.search(request.cr, request.uid, domain))
pager = website.pager(url="/shop/category/%s/" % cat_id, total=product_count, page=page, step=step, scope=7)
pager = website.pager(url="/shop/category/%s/" % cat_id, total=product_count, page=page, step=step, scope=7, url_args=post)
product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'])

View File

@ -102,7 +102,7 @@
<t t-call="website.pager" >
<t t-set="classname">pull-left</t>
</t>
<form action="/shop/" method="get" class="navbar-search pull-right">
<form action="/shop/" method="get" class="navbar-search pull-right pagination">
<input type="text" name="search" class="search-query span2" placeholder="Search" t-att-value="search or '' or ''"/>
</form>
</div>