On Tue, Dec 22, 2009 at 4:05 PM, uramagget <[email protected]> wrote:
> As far as functionality goes for webhelpers.paginate, would it not be
> preferable, at least for the sake of flexibility if the user was given
> the option of specifying whether or not the first page should be a
> link? Looking at the current code, a separate parameter could work,
> defaulting to False, although I've only glanced at the relevant areas.

What would be the purpose of this?  To suppress the navigator if
there's only one page?  To make the current page be a link to itself?

You can do the former with a Mako function like this:

===
## ************ PAGED REGION *******************
<%def name="paged(page, whats, route_name, query_params)">
<%
    """Put a paged section on a webpage, with links to the other pages.

       page:        A Page object from Christoph Haas' 'paginate' package.
       whats:       A plural word describing the elements in the page.
       route_name:  Name of route for URL generation.
       query_params:      Dict of query params for URL generation.

       Your controller action should look for the 'partial' query parameter.
       If present, return the paged region indicated by its value rather than
       the entire HTML page.
    """
%>
% if page.item_count == 0 or page.first_item is None:
<p class="instructions">No ${whats}
${"found" if page.item_count == 0 else "on this page"}.</p>
<%   return   %>
% endif
  <%def name="navigator()">
    <%
        params = query_params or {}
        prev = max(page.page-1, page.first_page)
        next = min(page.page+1, page.last_page)
        is_first_page = page.page == page.first_page
        is_last_page = page.page == page.last_page
    %>
## Put your navigator HTML here
  </%def>
<div id="dynamic">
    <div>
        Displaying ${whats} ${page.first_item}
        to ${page.last_item} of ${page.item_count}.
    </div>
    <div>${navigator()}</div>
    <div style="margin: 0.5em 0">
${caller.body()}
    </div>
    <div>${navigator()}</div>
</div>
</%def>
===

Call it with a <%call> whose body is the paged content.  This function
puts a navbar at the top and bottom of the page, and replaces the
entire region with a message if there are no records.  You can put an
'if' in the navigator function if you want to do something special if
there's only one page.

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