次のようなコントローラーとメソッドを指定します。
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')
そして、次のようなテンプレート:
<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>
TG2 がページネーション リンクを正しく生成していることがわかりますが、ページネーションは最初のデコレータだけを使用してページを変更し、2 番目のデコレータは無視します。以前にこの問題に直面した人はいますか?
ありがとう。