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
> 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>
It works :)
--
Fred
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
mail: ronald AT checkandshare DOT com
blog: http://www.checkandshare.com/blog
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)
Search Pagination
http://trac.turbogears.org/turbogears/wiki/Search_Pagination
--
Fred
> 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>
> 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>
________________________________
> 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>
http://turbogears.blogspot.com/2005/11/simple-pager-decorator.html
http://tinyurl.com/np758
Ciao
Michele
> 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>
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.
> 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>
"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....
IIRC, it generates a query with OFFSET and LIMIT. Take a look at it.
--
Jorge Godoy <jgo...@gmail.com>
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
> 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.
> 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.
I wonder if something like this can go in standard TG distribution.
HTH,
Max.