sqlhtml.py - breadcrumbs exception when using smartgrid format + lambda

76 views
Skip to first unread message

Roderick

unread,
Feb 14, 2012, 5:00:15 AM2/14/12
to web2py-users
Hi!

When I use a lambda function for the "format" attribute of a table,
display the table in a smartgrid and click a linked table, the
referring table is shown by id instead of by the lambda
representation. The format works fine elsewhere (e.g. in smartgrid
rows). I think this part of sqlhtml.py is generating an exception
which is why I'm getting the index:

line 1918 (v1.99.4):
line 1942 (trunk on 14 Feb 2012)
try:
name = db[referee]._format % record
except TypeError:
name = id
breadcrumbs += [A(T(db[referee]._plural),
_class=trap_class(),

_href=URL(args=request.args[:nargs])),
' > ',
A(name,_class=trap_class(),

_href=URL(args=request.args[:nargs]+[

'view',referee,id],user_signature=True)),
' > ']

Is this a bug?

Thanks!

Roderick

unread,
Feb 14, 2012, 7:18:48 AM2/14/12
to web...@googlegroups.com
Being a noob at Python and Web2py, this is the best I could come up with:

In sqlhtml.py, insert the 2nd try block (below "name = db[referee]._format % record") as follows:


                    try:
                        name = db[referee]._format % record
                    except TypeError:
                        try:
                            name = db[referee]._format(record)

                        except TypeError:
                            name = id

This seems to work for "format=%(name)s" and "format=lambda record: record.name" formats.

If anyone has a better/cleaner solution I'd like to hear it..

Thanks!

Anthony

unread,
Feb 14, 2012, 8:57:30 AM2/14/12
to web...@googlegroups.com
Please post an issue here: http://code.google.com/p/web2py/issues/list

Massimo Di Pierro

unread,
Feb 14, 2012, 9:44:34 AM2/14/12
to web2py-users
Thanks fixed in trunk now.

Roderick

unread,
Feb 16, 2012, 4:26:02 AM2/16/12
to web2py-users
Hi Massimo and Anthony

Created the following issue:
http://code.google.com/p/web2py/issues/detail?id=663

Unfortunately the fix doesn't work on the breadcrumbs - still getting
the index - although it does work on row data...

Thanks & regards,

Roderick

On Feb 14, 4:44 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Cliff

unread,
Feb 16, 2012, 10:25:16 PM2/16/12
to web2py-users
Here's an alternative breadcrumb generator that handles object names
like this...

if len(request.args) > 0: # tune this value. grid & smartgrid use
longer arg lists
if 'name' in db[request.controller].fields:
item_name = 'editing ' + db[request.controller][args[-1]]].name
else:
item_name = 'editing item #' + request.args[-1]

bc_list.append(A(item_name, _href=URL(....))) #
Reply all
Reply to author
Forward
0 new messages