SQLFORM.grid field.represent not working with joined tables

56 views
Skip to first unread message

Paul Ellis

unread,
Feb 14, 2017, 6:42:22 PM2/14/17
to web2py-users
I have have a grid with a left outer join. So the row objects look like this:
<Row {'product': {'purchasecost': 72.0,
                  'monthlycost': 0.0,
                  'id': 92L,
                  'productname': 'Awesome Product'},
      'product_offer_item': {'discount': 0.0,
                             'optional': True,
                             'id': 172L,
                             'quantity': 99L}}>

I am trying to use represent to make some of them editable. For the optional checkbox it is like this:
    db.product_offer_item.optional.represent = lambda value, row: INPUT(_type='checkbox',
                                                                        _checked=value,
                                                                        _name='optional',
                                                                        _id=row.product.id
                                                                        )
and placed just before the grid is created. Now I am getting an Attribute Error from adding the ID to the checkbox. If I just ad the whole row as the ID it works and I get an ID which looks like the row object above (that's where I copied the details from) but when I try to access the row data to put the product.id as the ID it throws an error. I also can't access the sub object product or product_offer_item, I get the same error.

With the left outer join, the product.id is present for all rows, the product_offer_item details are not.

I haven't had this problem before and can't think of a way to add a row unique identifier any other way. 

Why am I getting an Attribute Error when I can clearly see the attributes.


Paul Ellis

unread,
Feb 15, 2017, 4:06:56 PM2/15/17
to web...@googlegroups.com
Here is the traceback:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
Traceback (most recent call last):
 
File "E:\web2py\gluon\restricted.py", line 227, in restricted
   
exec ccode in environment
 
File "E:\web2py\applications\OfferTool\views\offer/test.html", line 79, in <module>
 
File "E:\web2py\gluon\globals.py", line 430, in write
   
self.body.write(xmlescape(data))
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\html.py", line 963, in xml
   
(fa, co) = self._xml()
 
File "E:\web2py\gluon\html.py", line 955, in _xml
   
self.components])
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\html.py", line 963, in xml
   
(fa, co) = self._xml()
 
File "E:\web2py\gluon\html.py", line 955, in _xml
   
self.components])
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\html.py", line 963, in xml
   
(fa, co) = self._xml()
 
File "E:\web2py\gluon\html.py", line 955, in _xml
   
self.components])
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\html.py", line 963, in xml
   
(fa, co) = self._xml()
 
File "E:\web2py\gluon\html.py", line 955, in _xml
   
self.components])
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\html.py", line 963, in xml
   
(fa, co) = self._xml()
 
File "E:\web2py\gluon\html.py", line 955, in _xml
   
self.components])
 
File "E:\web2py\gluon\html.py", line 131, in xmlescape
   
return data.xml()
 
File "E:\web2py\gluon\packages\dal\pydal\objects.py", line 2344, in xml
    rv
= self.db.represent('rows_xml', self)
 
File "E:\web2py\gluon\packages\dal\pydal\base.py", line 1076, in represent
   
return self.representers[name](*args, **kwargs)
 
File "E:\web2py\gluon\sqlhtml.py", line 3329, in __init__
    r
= represent(field, r, record)
 
File "E:\web2py\gluon\sqlhtml.py", line 70, in represent
   
return f(value, record)
 
File "E:/web2py/applications/OfferTool/controllers/offer.py", line 331, in <lambda>
   
_id=row.product.id)
 
File "E:\web2py\gluon\packages\dal\pydal\objects.py", line 90, in __getattr__
   
raise AttributeError
AttributeError

And I should point out that if I do something like 'row.id' which should cause an Attribute Error I get a much shorter Traceback.

Paul Ellis

unread,
Feb 20, 2017, 5:04:24 PM2/20/17
to web2py-users
I still don't know what caused this. There was obviously something missing in the grid. I have come back to the problem after working around it with js and can't replicate the issue. It is now working.
Reply all
Reply to author
Forward
0 new messages