unordered list and pagination

232 views
Skip to first unread message

Annet

unread,
Apr 8, 2012, 4:00:26 AM4/8/12
to web...@googlegroups.com
I have an address book controller with a function that queries the database for addresses:

rows=db((db.Organization.nodeID==db.NodeKeyword.nodeID)&(db.Organization.nodeID==db.Address.nodeID)&\
(db.Organization.approved==True)&(db.NodeKeyword.word==request.vars.word)&\
(db.Address.locality==request.vars.locality)&(db.Address.addrType==PHYSICALADDR))\
.select(db.Organization.nodeID,db.Organization.name,db.Address.ALL,orderby=db.Organization.name)

In the view I'd like to do something like:

<ul>
<li>
Organization.name
Address.address
Address.postal-code Address.locality
</li>
<li>
Organization.name
Address.address
Address.postal-code Address.locality
</li>
<li>...</li>
</ul>

I'd like to display 12 addresses per page, so I need pagination. I had a look at the examples in the book, but I don't see how they make an unordered list page-able.

I hope one of you could provide me with a working example, or different approach to solve the problem.

Kind regards,

Annet

Annet

unread,
Apr 8, 2012, 5:50:26 AM4/8/12
to web...@googlegroups.com
Is there a way to implement this using twitter bootstrap's pagination component: http://twitter.github.com/bootstrap/components.html


Annet.

Massimo Di Pierro

unread,
Apr 8, 2012, 11:11:55 AM4/8/12
to web...@googlegroups.com
def index():
     query = (db.Organization.nodeID==db.NodeKeyword.nodeID)&(db.Organization.nodeID==db.Address.nodeID)&\
(db.Organization.approved==True)&(db.NodeKeyword.word==request.vars.word)&\
(db.Address.locality==request.vars.locality)&(db.Address.addrType==PHYSICALADDR)
     fields = (db.Organization.nodeID,db.Organization.name,db.Address.ALL)
     orderby = db.Organization.name
     grid = SQLFORM.grid(query,fields=fields,orderby=orderby,sortable=False,
                                             create=False,deletable=False,editable=False,
                                             searchable=False,paginate=12)
     return dict(grid=grid)

Annet

unread,
Apr 9, 2012, 2:45:50 AM4/9/12
to web...@googlegroups.com
Massimo,

Thanks for your reply. I like the solution, however, it results in the following ticket:

Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py", line 45, in <module>
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f()
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py", line 26, in index
grid=SQLFORM.grid(query,fields=fields,orderby=orderby,sortable=False,create=False,deletable=False,editable=False,searchable=False,paginate=12)
File "/Library/Python/2.5/site-packages/web2py/gluon/sqlhtml.py", line 1515, in grid
field_id = tables[0]._id
IndexError: list index out of range


Kind regards,

Annet

Massimo Di Pierro

unread,
Apr 9, 2012, 10:24:54 AM4/9/12
to web...@googlegroups.com
Please try trunk version (you appear to be using an older version). If the problem persists open a google code ticket about this.

massimo

Annet

unread,
Apr 10, 2012, 2:06:20 AM4/10/12
to web...@googlegroups.com
Massimo,


Please try trunk version (you appear to be using an older version). If the problem persists open a google code ticket about this.

I tried the trunk version, now I get another error:

 
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f
()
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py", line 21, in indexindex
searchable=False,paginate=12)
File "/Library/Python/2.5/site-packages/web2py/gluon/sqlhtml.py", line 1517, in grid
buttonexport='icon downarrow',
AttributeError: 'SQLALL' object has no attribute '_tablename'


Kind regards
,

Annet

Massimo Di Pierro

unread,
Apr 10, 2012, 9:39:04 AM4/10/12
to web...@googlegroups.com
can you show us addressbook.py around linke 56?
Message has been deleted

Annet

unread,
Apr 11, 2012, 1:37:39 AM4/11/12
to web...@googlegroups.com
Massimo,

Sorry, I clicked the post button, before writing a reply. In the old Google Groups I had the option to remove a post, it seems to no longer be available.

Anyway, line 56 is the first empty line at the end of addressbook.py

When I create an empty controller and just put the following function in it:

# coding: utf8

def index():
    query=(db.Organization.nodeID>2033)
    fields=(db.Organization.name)
    orderby=db.Organization.name
    grid=SQLFORM.grid(query,fields=fields,orderby=orderby,sortable=False,create=False,deletable=False,editable=False,\
    searchable=False,paginate=12)
    return dict(grid=grid)


I get this ticket when executing the function:

Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
  File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/mock.py", line 11, in <module>
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f
()
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/mock.py", line 8, in index
searchable=False,paginate=12)
File "/Library/Python/2.5/site-packages/web2py/gluon/sqlhtml.py", line 1577, in grid
if field._tablename in tablenames]
AttributeError: 'Expression' object has no attribute '_tablename'


Kind regards,

Annet

Massimo Di Pierro

unread,
Apr 11, 2012, 9:19:34 AM4/11/12
to web...@googlegroups.com
    fields=(db.Organization.name)

should be

    fields=(db.Organization.name, ) # <<< the commma

or

    fields=[db.Organization.name]

Annet

unread,
Apr 12, 2012, 10:53:58 AM4/12/12
to web...@googlegroups.com
Massimo,

Thanks for helping me solve the problem. This:


    fields=(db.Organization.name, ) # <<< the commma

... doesn't work. It had to be:

    fields=[db.Organization.name]

 
Kind regards,

Annet.
Reply all
Reply to author
Forward
0 new messages