you can use webhelpers.paginate to do this.

i wrote a decoration to wrap it.
you can use it like this:

@expose('xxxx.templates.book.home')
@paginate('books')
def home(self, **kw):
    books_query = DBSession.query(Book)
    return dict(page='home', books=books_query)

then 'books' in dict will be converted to a page object

------------------------------------------------------
code:

from webhelpers import paginate as p

class paginate(object):
    def __init__(self, *collections):
        self.collections = collections

    def __call__(self, f):
        def wrapped_f(*args, ** kw):
            d = f(*args, ** kw)
            for c in self.collections:
                if d.get(c):
                    page = p.Page(d[c], int(kw.get("p") or
1),items_per_page=10)
                    d[c] = page
            return d
        return wrapped_f


Yours
Faithfully

Jeffrey Hsu


On Tue, Jun 30, 2009 at 10:00 AM, jj.galvez <[email protected]> wrote:

>
> hi, I need help with pagination,
> I created a crud app following the example from the docs (http://
> www.turbogears.org/2.0/docs/main/Extensions/Crud/index.html?highlight=crud
> )
> but now I have so many things in my database that they don't all fit
> in a single page and I need pagination,  I tried to just add @pageinate
> ('unique_name') as a decorator, but when I call the page nothing shows
> up.  Any and all help is appreciated
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to