WebHelpers 1.3b1 is released, with some new Pyramid-compatible URL
generator classes and documentation for Paginate. Previously you had
to write your own callback function unless you're using Pylons.  The
Grid class is also updated to allow paging via a URL generator, and
the pylonslib Grid subclass is deprecated. There are also a couple
minor bugfixes.

Two URL generators are included; both are compatible with Pyramid.
``PageURL_WebOb`` takes a Request object.  ``PageURL`` takes a URL
path and query params dict for compatibility with all frameworks.

This release is a beta to test the new code and to wait for some
pending changes.

To use paginate with Pyramid:

    import webhelpers.paginate as paginate
    q = some_sqlalchemy_query_or_a_sequence
    current_page = int(request.params["page"])
    page_url = paginate.PageURL_WebOb(request)
    records = Page(q, current_page, url=page_url)

If you want qualified URLs (with the "scheme://host" prefix), do
``PageURL_WebOb(request, qualified=True)``. But you may get the wrong
scheme and host if you're behind a reverse proxy! (e.g., mod_proxy)

If you prefer your page number in the URL path rather than in a query
parameter, you'll have to use a framework-specific generator. The
following is suggested in the Paginate documentation:

    import webhelpers.paginate as paginate
    from pyramid.url import current_route_url
    def page_url(page):
        return current_route_url(request, page=page, _query=request.GET)
    q = SOME_SQLALCHEMY_QUERY
    current_page = int(request.matchdict["page"])
    records = Page(q, current_page, url=page_url)

This would work for route "/articles/{id}/page/{page}", overriding the
'page' variable but not the 'id' variable, and preserving the query
string.

There are some other WebHelpers tickets which I need help with if
anybody wants to volunteer:

- How to incorporate HTML 5's "data-" attributes into tag builders?
  
https://bitbucket.org/bbangert/webhelpers/issue/55/cant-pass-html5-data-attributes-to-tag

- How to incorporate HTML 5's boolean attributes in tag builders?
  https://bitbucket.org/bbangert/webhelpers/issue/46/html-5-enhancements

- 'disabled' option should be a boolean in tag builders, but for which tags?
  
https://bitbucket.org/bbangert/webhelpers/issue/50/htmltagsselect-disabled-true-false

- Bug in nl2br() if text contains "\r"
  https://bitbucket.org/bbangert/webhelpers/issue/28/nl2br-works-wrong

- escape() fails with non-ASCII Unicode characters. Is this something
we can fix without doing a lot of wrapping of MarkupSafe?
   https://bitbucket.org/bbangert/webhelpers/issue/57/escape-fails-with-unicode

- Request for a quoting function so that a substring containing '' can
be interpolated in a single-quoted string.
  
https://bitbucket.org/bbangert/webhelpers/issue/49/what-do-you-think-about-append-addslashes

- A couple FeedGenerator enhancement requests.
  
https://bitbucket.org/bbangert/webhelpers/issue/7/rss2-fields-for-feedgenerator
  
https://bitbucket.org/bbangert/webhelpers/issue/27/pretty-print-feedgenerator-output

I'd also like to rewrite paginate to factor out the database-specific
code and URL generation code and dump the legacy URL generation code,
but that's a largish task. It would also require some AJAX expertise
to make sure 'partial' still works.


Ergo^: I changed the Grid(url_generator=) arg to 'url' to match
paginate. I think you should take out the 'request' arg now so that
paginate and Grid are parallel. Grid should be able to use paginate's
URL generators.

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to