Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6959755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:18:49+00:00 2026-05-27T15:18:49+00:00

Give a controller and a method like: import genshi from pylons import tmpl_context, request,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:18:50+00:00Added an answer on May 27, 2026 at 3:18 pm

    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):

    from tg.decorators import Decoration
    from tg.paginate import Page
    from tg.util import Bunch, partial
    from tg import request
    
    class paginate(object):
        def __init__(self, name, use_prefix=False,
            items_per_page=10, max_items_per_page=0):
            self.name = name
            prefix = use_prefix and name + '_' or ''
            self.page_param = prefix + 'page'
            self.items_per_page_param = prefix + 'items_per_page'
            self.items_per_page = items_per_page
            self.max_items_per_page = max_items_per_page
    
        def __call__(self, func):
            decoration = Decoration.get_decoration(func)
            decoration.register_hook('before_validate', self.before_validate)
            decoration.register_hook('before_render', self.before_render)
            return func
    
        def before_validate(self, remainder, params):
            page_param = params.pop(self.page_param, None)
            if page_param:
                try:
                    page = int(page_param)
                    if page < 1:
                        raise ValueError
                except ValueError:
                    page = 1
            else:
                page = 1
    
            try:
                paginators_data = request.paginators
            except:
                paginators_data = request.paginators = {'_tg_paginators_params':{}}
    
            paginators_data['_tg_paginators_params'][self.page_param] = page_param
            paginators_data[self.name] = paginator = Bunch()
    
            paginator.paginate_page = page or 1
            items_per_page = params.pop(self.items_per_page_param, None)
            if items_per_page:
                try:
                    items_per_page = min(
                        int(items_per_page), self.max_items_per_page)
                    if items_per_page < 1:
                        raise ValueError
                except ValueError:
                    items_per_page = self.items_per_page
            else:
                items_per_page = self.items_per_page
            paginator.paginate_items_per_page = items_per_page
            paginator.paginate_params = params.copy()
            paginator.paginate_params.update(paginators_data['_tg_paginators_params'])
            if items_per_page != self.items_per_page:
                paginator.paginate_params[self.items_per_page_param] = items_per_page
    
        def before_render(self, remainder, params, output):
            if not isinstance(output, dict) or not self.name in output:
                return
    
            paginator = request.paginators[self.name]
            collection = output[self.name]
            page = Page(collection, paginator.paginate_page,
                paginator.paginate_items_per_page, controller='/')
            page.kwargs = paginator.paginate_params
            if self.page_param != 'name':
                page.pager = partial(page.pager, page_param=self.page_param)
            if not getattr(tmpl_context, 'paginators', None):
                tmpl_context.paginators = Bunch()
            tmpl_context.paginators[self.name] = output[self.name] = page
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the controller, method and queries from a URL array. Something
Give a base class Base , I want to write a method Test, like
Can someone please tell me how to invoke a method from the codeigniter controller
I called a method from another controller using this AnotherController oriCon = new AnotherController();
I have a method in my Controller which looks like this: @RequestMapping(value = /test,
To give an example of the kind of request that I can't figure out
i give users special URL with access key in it. users accessing the public
I have a route that looks like the following: map.newsletter '/newsletter', :controller => newsletter
I have a controller that looks like this for importing xml to my site:
redirect_to :controller=>'groups',:action=>'invite' but I got error because redirect_to send GET method I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.