10 messages in com.googlegroups.pylons-discussRe: Pagination research| From | Sent On | Attachments |
|---|---|---|
| Christoph Haas | 25 Jan 2007 07:13 | |
| Shannon -jj Behrens | 26 Jan 2007 17:15 | |
| Christoph Haas | 29 Jan 2007 06:53 | |
| dds | 02 Feb 2007 23:00 | |
| David Smith | 04 Feb 2007 18:37 | |
| Christoph Haas | 05 Feb 2007 02:28 | |
| Shannon -jj Behrens | 05 Feb 2007 12:57 | |
| Chris AtLee | 05 Feb 2007 13:43 | |
| David Smith | 05 Feb 2007 15:42 | |
| Christoph Haas | 18 Feb 2007 15:38 |
| Subject: | Re: Pagination research![]() |
|---|---|
| From: | Christoph Haas (emai...@public.gmane.org) |
| Date: | 01/29/2007 06:53:50 AM |
| List: | com.googlegroups.pylons-discuss |
UPDATE...
On Thursday 25 January 2007 16:13, Christoph Haas wrote:
I'm using SQLAlchemy and have defined my Table()s in models/__init__.py. To use the pagination I used
from webhelpers import pagination
in the lib/helpers.py. [...] Since the above query object was ugly I tried to feed the Table object directly:
domains_paginator, domain_set = \ h.pagination.paginate( model.powerdns_domains_table, page=0, per_page=100 ) set_count = int(domains_paginator.current) total_pages = len(domains_paginator)
This looks a lot cleaner but doesn't work. [...] NameError: global name 'func' is not defined
I found my mistake. What I tried was wrong:
model.powerdns_domains_table,
What would be right:
model.Domain.select(),
Unfortunately it wasn't clear to me what kind of object can be put into the pagination helper. After reading the sources of webhelpers.pagination.orm and working myself through more documentation of SQLAlchemy it became a bit clearer that the "assign_mapper" function adds the functions that the Query class in SQLAlchemy provides are added to the own SQL model. In other words: after mapping the model to the Python object I invented I can now use .select() on my model and get an SQLAlchemyLazyMapper (or is it SQLAlchemyLazyTable?) object back which is what paginate() expects. Phew.
The documentation at http://pylonshq.com/WebHelpers/module-webhelpers.pagination.html contains this example:
# In this case, Person is a SQLObject class, or it could be a list/tuple person_paginator, person_set = paginate(Person, page=1)
It wasn't very clear to me how that is supposed to work with SQLAlchemy. It must look like this:
person_paginator, person_set = \ h.pagination.paginate(model.Person.select())
Can we please add that example to the the webhelpers/pagination/orm.py module?
And while we are at it. The code reads:
return "You shouldn't have this"
If neither SQLObject or SQLAlchemy is installed or if the object given to the paginate() call is not what is expected this nonsense error message is returned. This makes you get ['Y', 'o', 'u', ' ', 's', 'h', ...] on the web page which is... erm... non-intuitive. Can't we raise a proper exception telling the programmer on how to do it right - or at least what is wrong? You can't imagine my face when my screen suddenly told me I'm stupid. :(
Kindly Christoph




