Forum OpenACS Q&A: template::paginator

Collapse
Posted by Dave Bauer on
Has anyone ever used the template::paginator procs? There doesn't seem
to be any documentation showing how to use it to build a page.

Thanks.

Collapse
Posted by Don Baccus on
I haven't used it but have looked at it. It caches a list of keys and sets up all the "next" and "prev" links for you. Then inside the loop you select to get the right rows. The theory is that this second select is cheaper than your typical content selection because you only have to join or qualify using the single key (presumably perms etc were checked in the first query).

I looked at it for use with Greenpeace and decided to write a caching db_multirow instead.

I think we should look to a better solution than the existing paginator proc but that doesn't mean you shouldn't necessarily use it.

Collapse
Posted by Roberto Mello on
Well, I'm trying to figure out how to use template::paginator but I haven't been able to.

The reason I'm looking at (which is the same as to why dave was looking too) is to change the forums user interface. Right now in forums-view it displays ALL threads in that forum. That means waiting ten minutes for all the threads in the OpenACS Q&A forum (http://dev.openacs.org/forums/forum-view?forum_id=14013) to show up, since they are in a table (I hope Ben is reading this 😊)

I haven't been able to figure out template::paginator. It looks good, but there's no documentation (except for comments outside of ad_proc!) or examples that I can find. I tried a template::paginator::create followed by a template::paginator::get_page_count (IIRC) and kept getting errors until I gave up.

We only have a couple days to get everything setup before LinuxWorld, so I decided to just repeat the queries. Is your cached db_multirow proc available anywhere. Perhaps I could use that instead.

Karl Goldstein is the author of the paginator procs. Perhaps he has an example. Anyone has his e-mail address?

Collapse
Posted by Dan Wickstrom on
Say what you will about cms, it has alot of nice stuff in it.  Look at packages/cms/www/modules/sitemap/index.tcl for an example that uses a paginator.

It appears that the paginator does a single query and caches the result.  The results are then returned as multirow datasource.

Collapse
Posted by Roberto Mello on
Yes, that's what paginator does. It uses the templating::query stuff insteaf of theDB api though, but I'm not going to mess with that now. Just want to get something working.

Thanks for the tip Dan.

Collapse
Posted by Dan Wickstrom on
I modified the template::query api to use db_exec, so it's completely compatible with the standard db api used throughout the rest of the toolkit.  I know, we've decided to phase out the template db api, but it's not a reason to not use the paginator procs.  After all, a switch to the standard db api from the template db api would be completely transparent at the paginator interface level.
Collapse
Posted by Roberto Mello on
Dan,

Thanks a lot for that example. Paginator made a whole lot more sense after looking at it. Even the comments on the paginator procs are missing some important information. To me, it's one of those things that I really can't "get" until I see an example.

Now that I understand it, I actually like it a lot. I added a few lines of code to the forum-view page and voila! It's paginated. You can see the end result here: http://dev.openacs.org/forums/forum-view?forum_id=14013

It loads nice and fast, the query is cached, the output is pretty, everybody is happy. I'll make sure to commit this to the forums CVS if  there are no objections (Ben, arjun?).

I'll make sure to write documentation for paginator. It can be very very useful stuff. I think I'll add paginator stuff to the message-view too.

Collapse
Posted by Dan Wickstrom on
Excellent job on the new site by the way.  It's really starting to shape up nicely.
Collapse
Posted by Lars Pind on
Roberto,

I'm looking at using paginator now ... did you write up documentation on it? In-line in the file, or did you write a "here's how to paginate your page" page?

/Lars

Collapse
Posted by Deds Castillo on
My boss pointed me to this thread when I asked if he has any generic pagination stuff. I can say that the acs-templating paginator-procs works pretty well for my needs. I have a couple of bug fixes and improvements though. I've already submitted a patch here

Here is a summary of the changes on this patch:

  • corrects incorrect return value in get_page_count
  • adds a get_pages_info proc which is the counterpart of get_context for non-contextual page objects
  • adds a get_row_last proc which gives the last row in a current page
  • improved parameter explanation on some procs
  • corrects a typo in init proc which messes up initialization of non-contextual page objects
  • modified get data so that it is not restricted on integer keys, thus allowing it to be used on queries which don't have primary keys by building your own unique keys

No difference in affected file on both HEAD and oacs-4-6 branches so the patch can be applied on both.

Thanks.