Ñò
{XHc @ s d Z d Z d Z d Z d Z d d k Z d d k Z y d d k l Z Wn# e j
o d d k
l Z n Xd d k l Z l
Z
y d d k Z Wn
e Z n
Xe i Z d d „ Z d
e f d „ ƒ YZ d e f d
„ ƒ YZ d e f d „ ƒ YZ d S( s¯
paginate: a module to help split up lists or results from ORM queries
=======================================================================
What is pagination?
---------------------
This module helps dividing large lists of items into pages. The user
is shown one page at a time and can navigate to other pages. Imagine you
are offering a company phonebook and let the user search the entries. If
the search result contains 23 entries but you may want to display no
more than 10 entries at once. The first page contains entries 1-10, the
second 11-20 and the third 21-23. See the documentation of the "Page"
class for more information.
How do I use it?
------------------
One page of items is represented by the *Page* object. A *Page* gets
initalized with two parameters at least:
- the collection of items to pick a range from
- the page number that is required (default is 1 - the first page)
A simple example (ipython session)::
# Set up the routes context (only if you are not using a Pylons application)
>>> from routes import Mapper; mapper=Mapper(); mapper.connect(':controller')
# Create a sample collection of 1000 items
>>> my_collection = range(1000)
# Create a Page object for the 3rd page (20 items per page is the default)
>>> my_page = Page(my_collection, page=3)
# The page object can be printed directly to get its details
>>> my_page
Page:
Collection type:
(Current) page: 3
First item: 41
Last item: 60
First page: 1
Last page: 50
Previous page: 2
Next page: 4
Items per page: 20
Number of items: 1000
Number of pages: 50
# Print a list of items on the current page
>>> my_page.items
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]
# The *Page* object can be used as an iterator:
>>> for my_item in my_page: print my_item,
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# On a web page you will want to use a "pager" that creates links that
# the user can click on to load other pages in the set.
# [The ">>" prompt is to hide untestable examples from doctest.]
>> my_page.pager()
1 2 [3] 4 5 .. 50 (this is actually HTML)
# The pager can be customized:
>> my_page.pager('$link_previous ~3~ $link_next (Page $page of $page_count)')
1 2 [3] 4 5 6 .. 50 > (Page 3 of 50)
Please see the documentation on *Page* and *Page.pager()*. There are many
parameters that customize the Page's behavior.
Can I use AJAX / AJAH?
------------------------
Yes. See *partial_param* and *onclick* in *Page.pager()*.
Notes
-------
Page numbers and item numbers start at 1. This concept has been used
because users expect that the first page has number 1 and the first item
on a page also has number 1. So if you want to use the page's items by
their index number please note that you have to substract 1.
This module is the successor to the deprecated ``webhelpers.pagination``
module. It is *NOT* API compatible.
This version of paginate is based on the code from
http://workaround.org/cgi-bin/hg-paginate that is known at the
"Paginate" module on PyPi.
s 0.3.6s
2008-05-01s( Christoph Haas s@ Copyright (c) 2007,2008 Christoph Haas iÿÿÿÿN( t Template( t literalt HTMLc C s³ t | t t f ƒ o | St i d ƒ p t i d ƒ oh t | t i i i ƒ o t | ƒ St | t i
i i ƒ p t | t i
i i
ƒ o t | | ƒ Sn t d ƒ ‚ d S( si
Auto-detect the kind of object and return a list/tuple
to access items from the collection.
s 0.4s 0.5s³ Sorry, your collection type is not supported by the paginate module. You can either provide a list, a tuple, an SQLAlchemy 0.4 select object or an SQLAlchemy 0.4 ORM-query object.N( t
isinstancet listt tuplet sqlalchemy_availablet
startswitht
sqlalchemyt ormt queryt Queryt _SQLAlchemyQueryt sqlt
expressiont CompoundSelectt Selectt _SQLAlchemySelectt TypeError( t objt sqlalchemy_session( ( s7 /usr/lib/python2.6/site-packages/webhelpers/paginate.pyt get_wrapper s R c B s, e Z d Z d d „ Z d „ Z d „ Z RS( sM
Iterable that allows to get slices from an SQLAlchemy Select object
c C s? t | t i i i ƒ p t d ƒ ‚ n | | _ | | _ d S( Ns¤ If you want to page an SQLAlchemy 'select' object then you have to provide a 'sqlalchemy_session' argument. See also: http://www.sqlalchemy.org/docs/04/session.html( R R R t scopingt
ScopedSessionR R R ( t selfR R ( ( s7 /usr/lib/python2.6/site-packages/webhelpers/paginate.pyt __init__« s c C sg t | t ƒ p
t d ‚ n | i } | i | i } | i i | ƒ i | ƒ } | i i | ƒ i
ƒ S( Ns) __getitem__ without slicing not supported( R t slicet Exceptiont startt stopR t offsett limitR t executet fetchall( R t rangeR R t select( ( s7 /usr/lib/python2.6/site-packages/webhelpers/paginate.pyt __getitem__´ s
c C s | i i | i ƒ i S( N( R R R t rowcount( R ( ( s7 /usr/lib/python2.6/site-packages/webhelpers/paginate.pyt __len__¼ s N( t __name__t
__module__t __doc__t NoneR R$ R&