can results page be split up?

11 views
Skip to first unread message

geekbuntu

unread,
Nov 7, 2009, 10:22:38 AM11/7/09
to web.py
i have a wicked long list of used books - wondering if i can sort them
with links?

http://pairadice.no-ip.org:8080/books

(around 4500)

Angelo Gladding

unread,
Nov 7, 2009, 2:09:07 PM11/7/09
to we...@googlegroups.com
Can you clarify what it is you mean by "sort them with links"? Are you dealing w/ raw HTML or are you sending an unsorted list to a template?
--
Angelo Gladding
ang...@gladding.name
http://angelo.gladding.name/
E69E 47E8 5C3A 96E5 C70F
D931 F35C ACBA 6F39 9611

Greg Milby

unread,
Nov 7, 2009, 3:15:15 PM11/7/09
to we...@googlegroups.com
it's a fetchall returned from a mysql query (so raw rows that are just being listed out in a <ol><li></li>.... for the time being)

Greg Milby

unread,
Nov 7, 2009, 3:16:16 PM11/7/09
to we...@googlegroups.com
here's the link of the raw query:




On Sat, Nov 7, 2009 at 2:09 PM, Angelo Gladding <ang...@gladding.name> wrote:

Greg Milby

unread,
Nov 7, 2009, 4:55:47 PM11/7/09
to we...@googlegroups.com
actually i was trying to learn how to paginate in webpy.

On Sat, Nov 7, 2009 at 2:09 PM, Angelo Gladding <ang...@gladding.name> wrote:

Leon Waldman

unread,
Nov 7, 2009, 5:28:12 PM11/7/09
to we...@googlegroups.com
Hi,

AFAIK, you can do it on the SQL...

Cheers

--
Leon Waldman
SysAdmin Linux - Arquiteto de Infra-Estrutura & TI.

Greg Milby

unread,
Nov 7, 2009, 7:56:09 PM11/7/09
to we...@googlegroups.com
what is afaik?

alexander lind

unread,
Nov 7, 2009, 7:58:04 PM11/7/09
to we...@googlegroups.com
as far as i know.

Greg Milby

unread,
Nov 7, 2009, 9:02:11 PM11/7/09
to we...@googlegroups.com
ah - ty

Angelo Gladding

unread,
Nov 7, 2009, 10:24:41 PM11/7/09
to we...@googlegroups.com
As raw SQL:

SELECT * FROM `books` ORDER BY `title` ASC LIMIT 0, 10
SELECT * FROM `books` ORDER BY `title` ASC LIMIT 10, 20

Using web.db:

db.select('books', order='title', offset=0, limit=10)
db.select('books', order='title', offset=10, limit=20)

see http://webpy.org/cookbook/select

Try something like this:

paths = ('/books', 'Books')
app = web.application(paths, globals())

class Books:
  def GET(self):
    """
    >>> assert app.request('/books?p=4').status == '200 OK'

    """

    try:
      offset = web.input('p').p * 10
    except web.badrequest:
      return list(db.select('books', order='title'))
    return list(db.select('books', order='title', offset=offset, limit=10))

Let me know if that helps.

Anand Chitipothu

unread,
Nov 8, 2009, 12:19:10 AM11/8/09
to we...@googlegroups.com
> Try something like this:
>
> paths = ('/books', 'Books')
> app = web.application(paths, globals())
>
> class Books:
>   def GET(self):
>     """
>     >>> assert app.request('/books?p=4').status == '200 OK'
>
>     """
>     try:
>       offset = web.input('p').p * 10
>     except web.badrequest:
>       return list(db.select('books', order='title'))
>     return list(db.select('books', order='title', offset=offset, limit=10))
>
> Let me know if that helps.

Small correction.

web.input('p').p returns a string. It must be converted to int before
multiplying with 10.
Also p must be optional parameter.

try:
p = int(web.input(p=0).p)
except ValueError:
p = 0

offset = p*10

Justin Caratzas

unread,
Nov 7, 2009, 10:58:17 PM11/7/09
to we...@googlegroups.com

or using javascript/JQuery, if you use a standard html table

Justin Caratzas

Greg Milby

unread,
Nov 8, 2009, 6:09:09 AM11/8/09
to we...@googlegroups.com
the query is getting this error:

<type 'exceptions.SyntaxError'> at /

('invalid syntax', ('/media/ST250x01/BACKUP/webpy/myapp.py', 24, 43, " showbooks = db.select('books' order='title', offset=10, limit=20)\n"))



here's how i'm using it:
 16 class index:
 17     def GET(self):
 18         welcome = 'Welcome'
 19         return render.index(welcome)
 20
 21 class books:
 22     def GET(books):
 23         db = web.database(dbn='mysql', user='root', pw='', db='books    ')
 24         showbooks = db.select('books' order='title', offset=10, limit=20)
 25         return render.books(showbooks)

Greg Milby

unread,
Nov 8, 2009, 6:10:50 AM11/8/09
to we...@googlegroups.com
nvm - i forgot a comma - thank you
will try your code below - adapt it to this. thanks for the help

Greg Milby

unread,
Nov 8, 2009, 6:19:53 AM11/8/09
to we...@googlegroups.com
i tried that - liked the idea, but it didn't go well.
i wrote  ascript to make the js (jQuery) data format - but if you look, it displays tons of empty pages at the end, was never able to figure out why - data is formatted to jQuery spec's
http://pairadice.no-ip.org/booknook/virt/

Justin Caratzas

unread,
Nov 8, 2009, 2:19:39 PM11/8/09
to we...@googlegroups.com
I'm assuming you got that problem fixed, because I just checked that link and it seems to work fine. The last 8 pages or so have data.

Justin

ps. Is this for the Book Nook franchise of used book stores? I love that place.

Greg Milby

unread,
Nov 8, 2009, 12:32:40 PM11/8/09
to we...@googlegroups.com
yes, i actually discovered what was wrong on the jquery pagination.  i may run with that since it would reduce the load on the webserver. thank you

Angelo Gladding

unread,
Nov 8, 2009, 12:58:03 PM11/8/09
to we...@googlegroups.com
Keep in mind non-js users!! :) The load is likely to be mostly on the database end anyway.
no-js.png

Greg Milby

unread,
Nov 8, 2009, 1:13:44 PM11/8/09
to we...@googlegroups.com
creating, handling and manipulating the db requests is the bulk of my load... i do not mind it, but why push spikes if i don't have to?

Greg Milby

unread,
Nov 8, 2009, 5:43:15 PM11/8/09
to we...@googlegroups.com
i would still like to know how to paginate in python *if anyone has figured it out - even though i will probably use jquery. i do not know where to begin with passing the links/code in and out of the template layer...


 21 class books:
 22     def GET(books):
 23         db = web.database(dbn='mysql', user='root', pw='', db='books')
 24         showbooks = db.select('books', order='title', offset=10, limit=20)
 25         return render.books(showbooks)

Justin Caratzas

unread,
Nov 8, 2009, 9:12:01 PM11/8/09
to we...@googlegroups.com
use a hidden field for the current page number, then set the offset to page * limit. atleast, thats how i've seen it done before. that could be taken a step further by ajax.

Justin
Reply all
Reply to author
Forward
0 new messages