Give a controller and a method like:
import genshi
from pylons import tmpl_context, request, url
import re
from tg import expose, flash
from tg.controllers import redirect
from tg.decorators import validate
import tw.forms as twf
from tw.forms.datagrid import DataGrid
from tg.decorators import paginate
from tg.i18n import ugettext as _
from repoze.what.predicates import has_permission
from interlock.lib.base import BaseController
assigned_seller_product_grid = DataGrid(fields=[
('Product Name', 'name'),
('Producer', 'producer'),
])
unassigned_seller_product_grid = DataGrid(fields=[
('Product Name', 'name'),
('Producer', 'producer'),
])
class SellerController(BaseController):
allow_only = has_permission('manage')
@paginate("unassigned", items_per_page=5, use_prefix=True)
@paginate("assigned", items_per_page=5, use_prefix=True)
@expose('demo.templates.sellers.products')
def products(self, uid = None, **kw):
seller = uid is not None and DBSession.query(SellerModel).filter_by(uid=uid, deleted=False).first()
if uid is not None and not seller:
flash(_('No Seller ID Defined'), 'warning')
redirect('/seller/')
unassigned = DBSession.query(ProductModel).filter(~ProductModel.sellers.any(SellerModel.uid == seller.uid)).filter(ProductModel.deleted == False)
assigned = DBSession.query(ProductModel).filter(ProductModel.sellers.any(SellerModel.uid == seller.uid)).filter(ProductModel.deleted == False)
return dict(seller=seller,
assigned=assigned,
unassigned = unassigned,
assigned_grid=assigned_seller_product_grid,
unassigned_grid=unassigned_seller_product_grid,
page='seller')
And a template like:
<h1>Assigned Products</h1>
<div py:if="assigned">${assigned_grid(assigned)}</div>
<div>${tmpl_context.paginators.assigned.pager(page_param='assigned_page')}</div>
<h1>Unassigned Products</h1>
<div py:if="unassigned">${unassigned_grid(unassigned)}</div>
<div>${tmpl_context.paginators.unassigned.pager(page_param='unassigned_page')}</div>
I see TG2 generate correctly the pagination links, but the pagination simply change page just using the first decorator, ignoring the second one. Does anyone faced this problem before ?
Thanks.
The current @paginate decorator on TG doesn’t permit to handle multiple paginators on the same page. A new version of the decorator will be available from the next release. In the mean time you can replace the @paginate decorator with the following implementation (just save it as myproject.lib.paginate and import it instead of tg.decorators.paginate):