Pagination

3 views
Skip to first unread message

JohnG

unread,
Apr 8, 2011, 4:11:38 PM4/8/11
to Whirlwind
Thanks to everyone in involved in Whirlwind, I've been working with
the framework for just over a week now and I've had nothing but fun
and fast progress on my project.

Obviously doc's are still thin on the ground, and this will improve in
time I'm sure. I have a question about Pagination as mentioned here:

https://github.com/trendrr/whirlwind/wiki/Whirlwind-Features

Who/What provides pagination, I've done some searching but can't find
it as a feature of Mako which is where I kinda expected to see it?

Thanks.

Matt Dennebaum

unread,
Apr 8, 2011, 5:18:22 PM4/8/11
to whirlw...@googlegroups.com
Hi John,

Great to hear your finding whirlwind fun/useful. Post a link on to the
group if you get something running your willing to share. Since were
such a new project it would be really awesome to start seeing some work
that people are leveraging the framework for.

Your observation about our docs being thin is def 100% correct... they
could be a whole lot better. And it def high up on the todo list. :)
That said as your working through the process of getting your app up and
running if you feel like helping out jot down your notes and
observations and we will add them to the wiki. Any and all contributions
to the docs would be greatly appreciated and would garner major brownie
points.

Now to the meat of your question, the pagination setup is pretty
straight forward. It's all centered around the whirlwind.view.Paginator
class. The Paginator object takes a mongo collection and provides you
with convenient paging functions that you would expect and have prob
seen in other frameworks.

For instance:
page() - gets the current page of documents
page_count() - get the total number of pages available
has_previous() & has_next() - this tells you if previous or next pages
are available. helpful when building out your paging controls.
previous_page() & next_page() - gets the page number for the previous
and next pages. helpful when generating paging back&next links
previous_page_link & next_page_link - builds you a link to the previous
and next pages

This should hopefully give you the tools to get you started. Normally
the approach we take is to create a pagination_footer.html include or
component that we then reuse as needed for different list based data.

You can also check out the whirlwind.core.request.BaseRequest.paged_list
function. This takes some params and builds a paginator object based on
selecting back segments of data using the skip and limit functions built
into mongo. A note here is that if your collection gets big this can be
a performance hit. We are prob going to be refactoring soon to use a
more efficient query.

best,
Matt

--

Matt Dennebaum, Chief Technology Officer
Wiredset * 425 West 13th Street Suite 504 * NY NY 10014

tel: 212.242.3400 ext: 123 * fax: 212.242.3464 * cel: n/a
W3: wiredset.com * e: ma...@wiredset.com * aim: mdennebaum2

Linkedin: http://www.linkedin.com/in/dennebaum

--

Matt Dennebaum

unread,
Apr 8, 2011, 8:13:28 PM4/8/11
to whirlw...@googlegroups.com
I just pushed an update to the paging helper functions.
https://github.com/trendrr/whirlwind/commit/8bd17fc4d3897f3d18da0de7592154311c58fad8

Added a sliced_list helper to more efficiently let you slice up large
document collections (based on min and max document ids). Unlike the
paged_list helper function it returns a slice of the collection instead
of a Paginator object. So it will take a bit more manual labor to use
this method for the time being. I'll try to hack up a alternate version
of the Paginator that will work with the sliced method soon.

Also please note that I moved the paged_list, sliced_list and
delete_selected helper functions to a new
whirlwind.core.request.RequestHelpers class. This is all pretty untested
so please submit a ticket on github if you see any weirdness.

best,
Matt

Matt Dennebaum

unread,
Apr 9, 2011, 10:29:21 AM4/9/11
to whirlw...@googlegroups.com
Just added a simple example of working with a Paginator to the docs page
on the wiki. Should help you on your way.

https://github.com/trendrr/whirlwind/wiki/Docs

best,
Matt

--

Linkedin: http://www.linkedin.com/in/dennebaum

--

Reply all
Reply to author
Forward
0 new messages