[albatross-users] Having trouble implementing pagination

Michael C. Neel neel at mediapulse.com
Wed Oct 1 00:12:12 EST 2003


I'm, not %100 on this, but yoo should be able to pass the fetchall()
straight to the al-for.  I do this all the time with MySQLdb, using the
normal cursor but that should make no difference here.

<al-for expr="c.fetchall()" iter="row" pagesize="20">
	<al-exec expr="record = row.value()">
	A: <al-value expr="record['a']">
</al-for>

..should work ok.  I say should because I don't use the dict cursor, but
iirc it returns a tuple of dicts, which should be just fine with the
Iterator class of albatross.

The gothca here is that the query will be preformed for every page
(which you can work around) and the entire result set will be stored in
the session (which you can't work around).  One of my goals is to create
a SQLIterator class to use in my AXE module that makes uses of LIMIT in
MySQL to only query what is shown.  That and add first, last, and
goto_page to optios along nexppage and prevpage.  Just a matter of
getting the time ;)

Mike

> -----Original Message-----
> From: Sheila King [mailto:sheila at thinkspot.net] 
> Sent: Tuesday, September 30, 2003 3:40 AM
> To: albatross-users at object-craft.com.au
> Subject: [albatross-users] Having trouble implementing pagination
> 
> 
> OK, I'm tearing my hair out and am about to give up for 
> tonight and go to 
> bed. LOL. Should have probably done that a couple of hours 
> ago. Oh, well.
> 
> I just can't seem to get pagination with the al-for tag to work.
> 
> I understand that I need some sort of sequence type that has 
> both __len__ 
> and __getitem__ methods.
> 
> I'm returning a result of several rows in a MySQLdb object using the 
> Dictionary Cursor types.
> 
> A typical query result, after using fetchall() to get all the 
> results, 
> would be something like this:
> 
> mydicts = ({'a': 1}, {'b': 2})
> 
> I have a class, that I use on individual dictionaries, such 
> as the result 
> of a fetchone() command, that works really nicely. That class 
> works fine by 
> itself.
> 
> However, today I tried to make some kind of a class that is a 
> list of those 
> dictionary objects, because I want to iterate over them and 
> use pagination. 
> But I am totally unable to have any kind of success at this.
> 
> I tried this:
> 
> class myclass(list):
>     def __getitem__(self, x):
>         return self[x]
> 
> But the above TOTALLY does not work and just recurses like 
> mad until I hit 
> the maximum recursion level.
> 
> I tried a bunch of other stuff too. <sigh>
> 
> If someone can toss me a hint, I'd sure appreciate it.
> 
> Thanks,
> 
> -- 
> Sheila King
> http://www.thinkspot.net/sheila/
> http://www.k12groups.org
> 
> _______________________________________________
> Albatross-users mailing list
> Albatross-users at object-craft.com.au
> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albat
ross-users



More information about the Albatross-users mailing list