[Question] Search Pagination

0 views
Skip to first unread message

gasolin

unread,
Mar 21, 2006, 9:59:08 PM3/21/06
to TurboGears
I wanna to make a "Search Pagination" with SQLObject and kid.

Expect result is: "| 0 | 1 | 2 | 3 |"

The question is "How to select ten entries as a set and then offset to
next set"?
I tried the "Class.select(expr.., limit=10)" but nothing happen at all.


my controller.py expose function is:

a = TableEntry.select(TableEntry.q.fieldA == True, orderBy='fieldB')
return dict(context = a)

my kid template is

| <span py:for = " i in range((context.count()/10)+1)"> <a
href="/">${i}</a> | </span>

which context.count() will return total queried entry numbers.


--
Fred

Jorge Godoy

unread,
Mar 21, 2006, 10:16:40 PM3/21/06
to turbo...@googlegroups.com
"gasolin" <gas...@gmail.com> writes:

> The question is "How to select ten entries as a set and then offset to
> next set"?
> I tried the "Class.select(expr.., limit=10)" but nothing happen at all.

Class.select(expr)[start:end]

So, for the first 10 records:

Class.select(expr)[0:10]

and for the next 10:

Class.select(expr)[10:20]

and so on.


--
Jorge Godoy <jgo...@gmail.com>

gasolin

unread,
Mar 21, 2006, 10:23:39 PM3/21/06
to TurboGears
Thanks for your quick response!

It works :)

--
Fred

gasolin

unread,
Mar 22, 2006, 2:59:24 AM3/22/06
to TurboGears
Hello:

I found another relate issue in "kid"

I want to add Prev/Next navigation in Search Pagination,

Expect result is: "Prev | 0 | 1 | 2 | 3 | Next"

,"Prev/Next" only shows if this action is possible.


I'd hvae to compare "set_end" and "set_size" to decide if I need to
show the "Next" button.

But I found I can't use small than (<) operator in "kid"'s "py:if"
statement.
(I guess the operator is mis-recognized as a html quote),
any idea?

Ronald Jaramillo

unread,
Mar 22, 2006, 3:29:01 AM3/22/06
to turbo...@googlegroups.com
Hi Gasolin (is that your name?)
You can use &#x03C; for < and &#x03E; for >
Cheers
Ronald

________________________________
Ronald Jaramillo
mail: ronald AT checkandshare DOT com
blog: http://www.checkandshare.com/blog

gasolin

unread,
Mar 22, 2006, 3:54:47 AM3/22/06
to TurboGears
Thanks! So it's an XML trick, though ;-)

I'll conclude the "Search Pagination" result on trac later.

Someone may want to write a widget(fastdata) version?

--
Fred Lin (<-- this is my name, 'gasolin' is my ID)

gasolin

unread,
Mar 22, 2006, 5:05:44 AM3/22/06
to TurboGears

Jorge Godoy

unread,
Mar 22, 2006, 8:33:12 AM3/22/06
to turbo...@googlegroups.com
"gasolin" <gas...@gmail.com> writes:

> But I found I can't use small than (<) operator in "kid"'s "py:if"
> statement.
> (I guess the operator is mis-recognized as a html quote),
> any idea?

"if x < 3" == "if 3 > x", for example...

--
Jorge Godoy <jgo...@gmail.com>

Jorge Godoy

unread,
Mar 22, 2006, 8:33:33 AM3/22/06
to turbo...@googlegroups.com
"gasolin" <gas...@gmail.com> writes:

> Thanks! So it's an XML trick, though ;-)
>
> I'll conclude the "Search Pagination" result on trac later.
>
> Someone may want to write a widget(fastdata) version?

I am trying to allocate some time for that... :-(

--
Jorge Godoy <jgo...@gmail.com>

Ronald Jaramillo

unread,
Mar 22, 2006, 9:01:46 AM3/22/06
to turbo...@googlegroups.com
Hi Jorge,
I'm actually working on it too...
Cheers
Ronald

________________________________

Jorge Godoy

unread,
Mar 22, 2006, 9:06:48 AM3/22/06
to turbo...@googlegroups.com
Ronald Jaramillo <ron...@checkandshare.com> writes:

> Hi Jorge,
> I'm actually working on it too...

So, please, do it. I'm a little busy and couldn't do that last week. :-)
Keep us informed and don't forget sending or commiting your patch ;-)

--
Jorge Godoy <jgo...@gmail.com>

Michele Cella

unread,
Mar 22, 2006, 9:22:58 AM3/22/06
to TurboGears
There is also a pager decorator around, never used it though:

http://turbogears.blogspot.com/2005/11/simple-pager-decorator.html
http://tinyurl.com/np758

Ciao
Michele

Jorge Godoy

unread,
Mar 22, 2006, 9:35:34 AM3/22/06
to turbo...@googlegroups.com
"Michele Cella" <michel...@gmail.com> writes:

> There is also a pager decorator around, never used it though:
>
> http://turbogears.blogspot.com/2005/11/simple-pager-decorator.html
> http://tinyurl.com/np758

I saw that but -- from memory -- it looked like it didn't optimze SQL queries
and queried everything to paginate later... If you start having hundreds of
thousands or millions of records, this is very undesirable -- specially for
several simultaneous users... But I might be wrong since it was a while ago
-- last year -- that I saw it.

--
Jorge Godoy <jgo...@gmail.com>

Jason Chu

unread,
Mar 22, 2006, 1:17:54 PM3/22/06
to turbo...@googlegroups.com
On Wed, Mar 22, 2006 at 11:35:34AM -0300, Jorge Godoy wrote:
>
> "Michele Cella" <michel...@gmail.com> writes:
>
> > There is also a pager decorator around, never used it though:
> >
> > http://turbogears.blogspot.com/2005/11/simple-pager-decorator.html
> > http://tinyurl.com/np758
>
> I saw that but -- from memory -- it looked like it didn't optimze SQL queries
> and queried everything to paginate later... If you start having hundreds of
> thousands or millions of records, this is very undesirable -- specially for

I don't know if I'd want to page through thousands or millions of records
anyway... ;)

Jason

--
If you understand, things are just as they are. If you do not understand,
things are just as they are.

Jorge Godoy

unread,
Mar 22, 2006, 12:22:49 PM3/22/06
to turbo...@googlegroups.com
Jason Chu <jc...@xentac.net> writes:

> I don't know if I'd want to page through thousands or millions of records
> anyway... ;)

I would. Of course, I'd like them to appear already sorted in the most useful
order (either from the last to the first or from the first to the last, it
depends on what you're doing).

In fact, there are cases where I have to be able to do that. Or include
several filtering options to reduce this number (even in a month there might
be some thousands of new records, so...).

--
Jorge Godoy <jgo...@gmail.com>

Jorge Vargas

unread,
Mar 22, 2006, 9:23:35 PM3/22/06
to turbo...@googlegroups.com
no actually it's a Kid thing, Kid templates must be valid XML files. therefore it takes those as open,close tags not as logical operators, I hate that about Kid.

Jorge Vargas

unread,
Mar 22, 2006, 9:25:16 PM3/22/06
to turbo...@googlegroups.com
On 3/21/06, Jorge Godoy <jgo...@gmail.com> wrote:

"gasolin" <gas...@gmail.com> writes:

> The question is "How to select ten entries as a set and then offset to
> next set"?
> I tried the " Class.select(expr.., limit=10)" but nothing happen at all.

Class.select(expr)[start:end]

I found that ugly. Your getting ALL your data to use only a part of it. It's elegant python code but it's horrible on performance if you want to get the results 10 at a time and you have 100 you will fetch 1000 records....


Jorge Godoy

unread,
Mar 22, 2006, 10:01:31 PM3/22/06
to turbo...@googlegroups.com
"Jorge Vargas" <jorge....@gmail.com> writes:

> I found that ugly. Your getting ALL your data to use only a part of it. It's
> elegant python code but it's horrible on performance if you want to get the
> results 10 at a time and you have 100 you will fetch 1000 records....

IIRC, it generates a query with OFFSET and LIMIT. Take a look at it.

--
Jorge Godoy <jgo...@gmail.com>

gasolin

unread,
Mar 23, 2006, 1:40:55 AM3/23/06
to TurboGears
Jorge:

I agree there are some area for performance improvement,
even the code there is intuitive for understand (and more like a
widget's structure?)

I've added an "Improve Performance" section on trac document, and draw
most "code" stuff from template.kid back to controller.py, it will
return less sets because we constrain it with [start:end] directly.
Hope it is not confuced.

I'm not good at tuning code, hope others can take care on it :-)

--
Fred

Alberto Valverde

unread,
Mar 23, 2006, 4:04:21 AM3/23/06
to turbo...@googlegroups.com
AFAIK SQLObject overloads the slicing operators so something like Class.select()[start:end] results in a query like: SELECT .... FROM  class LIMIT end-start+1 OFFSET start

However, I haven't tested it and I might be plain wrong :)

Alberto

Max Ischenko

unread,
Mar 23, 2006, 4:50:29 AM3/23/06
to TurboGears

> Ronald Jaramillo <ron...@checkandshare.com> writes:
>
> > Hi Jorge,
> > I'm actually working on it too...
>
> So, please, do it. I'm a little busy and couldn't do that last week. :-)
> Keep us informed and don't forget sending or commiting your patch ;-)

Actually, I implemented one myself, which is pretty generic and uses
DataGrid with a custom template. I need to consult first whether I can
share it.

Max Ischenko

unread,
Mar 23, 2006, 1:18:01 PM3/23/06
to TurboGears

Alberto Valverde wrote:

> AFAIK SQLObject overloads the slicing operators so something like
> Class.select()[start:end] results in a query like: SELECT .... FROM
> class LIMIT end-start+1 OFFSET start
>
> However, I haven't tested it and I might be plain wrong :)

You're right.

At least, I can confirm it for MySQL.

Max Ischenko

unread,
Mar 24, 2006, 12:47:18 AM3/24/06
to TurboGears
I posted description and source code excerpts of the solution we use
for paging in yet-to-be-released Spaca project online, see
http://maxischenko.in.ua/blog/entries/85/search-pagination-in-turbogears/.

I wonder if something like this can go in standard TG distribution.

HTH,
Max.

Reply all
Reply to author
Forward
0 new messages