Latest Version: 0.9.6.2

pagination

Pagination for Collections and ORMs

The Pagination module aids in the process of paging large collections of objects. It can be used macro-style for automatic fetching of large collections using one of the ORM wrappers, or handle a large collection responding to standard Python list slicing operations. These methods can also be used individually and customized to do as much or little as desired.

The Paginator itself maintains pagination logic associated with each page, where begins, what the first/last item on the page is, etc.

Helper functions hook-up the Paginator in more conveinent methods for the more macro-style approach to return the Paginator and the slice of the collection desired.


Attributes

a find_page

<_sre.SRE_Pattern object at 0x270cd20>

Functions

f paginate(collection, page=None, per_page=10, item_count=None, query_args=None, **options) ...

Paginate a collection of data

If the collection is a list, it will return the slice of the list along with the Paginator object. If the collection is given using an ORM, the collection argument must be a partial representing the function to be used that will generate the proper query and extend properly for the limit/offset.

query_args will be passed to the partial and is for use in generating limiting conditions that your collection object may take, the remaining unused keyword arguments will also be passed into the collection object.

Example:

# In this case, Person is a SQLObject class, or it could be a
# list/tuple
person_paginator, person_set = paginate(Person, page=1)

set_count = int(person_paginator.current)
total_pages = len(person_paginator)

Current ORM support is limited to SQLObject and SQLAlchemy. You can use any ORM you'd like with the Paginator as it will give you the offset/limit data necessary to make your own query.

If you fail to pass in a page value, paginate will attempt to find a page value in the QUERY_STRING from environ, or the Routes match dict. This feature only works if routes was used to resolve the URL.

Example:

# Using an SQLAlchemy object with assign_mapper under Pylons
# with an order_by passed in
c.paginator, c.people = paginate(model.Person,
                                 order_by=[model.Person.c.date])

WARNING: Unless you pass in an item_count, a count will be performed on the collection every time paginate is called. If using an ORM, it's suggested that you count the items yourself and/or cache them.

Classes

C Page(...) ...

Represents a single page from a paginated set.

This class contains 12 members.

C Paginator(...) ...

Tracks paginated sets of data, and supplies common pagination operations

The Paginator tracks data associated with pagination of groups of data, as well as supplying objects and methods that make dealing with paginated results easier.

A Paginator supports list operations, including item fetching, length, iteration, and the 'in' operation. Each item in the Paginator is a Page object representing data about that specific page in the set of paginated data. As with the standard Python list, the Paginator list index starts at 0.

This class contains 6 members.

C Window(...) ...

Represents ranges around a given page.

This class contains 4 members.

Modules

The webhelpers.pagination module exposes 2 submodules:

links
Pagination Link Generators
orm
ORM Wrappers

See the source for more information.

Top