1. Ben Bangert
  2. WebHelpers
  3. Issues
Issue #53 resolved

Paginate in Pyramid

cd34
created an issue

webhelpers was installed, tested a page that had pagination, first error is:

raise NotImplementedError("no URL generator available")

This appeared to rely on Pylons with a fallback to requiring routes. Once routes was easy_installed, the following error was received:

AttributeError: 'thread._local' object has no attribute 'mapper'

From discussions with mcdonc regarding flash messages, using thread._local appears to be incompatible with Pyramid.

Comments (7)

  1. Mike Orr

    Paginate doesn't understand how Pyramid generates URLs. You'll have to write a wrapper for ``pyramid.url.route_url()``. The wrapper spec and Page keyword arg is described in http://webhelpers.groovie.org/modules/paginate.html in the "URL Generator" section. When you have a wrapper that works, please post it here so that others can use it.

    The Flash helper and everything under ``webhelpers.pylonslib`` depends on Pylons magic globals, which don't exist in Pyramid. You'll have to rewrite those to pass the request/response/session in a Pyramid-friendly way. Or wait until somebody else has written them. I'll open a new bug report for that.

  2. Anonymous

    articles = paginate.Page(articles, page=int(request.params.get('page', 1)), items_per_page=15, url=get_page_url, item_count=article_count)

    By specifying a url callback, I am able to get this to work:

    def get_page_url(kw): from pyramid.threadlocal import get_current_request return update_params(get_current_request().path_info, kw)

  3. cd34 reporter

    Trying again to make sure the markup is set properly

    def get_page_url(**kw):
        from pyramid.threadlocal import get_current_request
        return update_params(get_current_request().path_info, **kw)
    
  4. Mike Orr

    After discussing this with Christoph Haas and Ben Bangert (Paginate's aothor and Pyramid's author respectively), we agreed to add new constructor args for the current URL path (string), and current query params (dict). If these are set, the navigator will generate a URL by overriding the 'page' query param. That will work with all frameworks. If may also accept a 'request' arg (WebOb Request), which has become standard among many Python web frameworks, to derive the same data. This all will only work for 'page' as a query param, not as a path variable. The latter is too dependent on Routes to support generically: there's no generic equivalent to a "path variable".

  5. Mike Orr

    Ergo reports that this works:

    def url_generator(**kw):
        return current_route_url(request, _route_name='browser_pages', **kw)
    paginate.Page(url=url_generator) -- all it takes to make it work :-)
    

    The user would have to do this in their view. Considering whether further automatic integration is feasable.

  6. Log in to comment