powerTable AttributeError: 'DAL' object has no attribute 'virtual'

896 views
Skip to first unread message

FERNANDO VILLARROEL

unread,
Sep 30, 2012, 9:11:28 PM9/30/12
to web...@googlegroups.com
Dear All.

I am trying to use PowerTable, but i am receiving the follow error:

Traceback (most recent call last):
File "/home/fvillarroel/www/web2py/gluon/restricted.py", line 209, in restricted
exec ccode in environment
File "/home/fvillarroel/www/web2py/applications/administrador/controllers/clientes.py", line 107, in <module>
File "/home/fvillarroel/www/web2py/gluon/globals.py", line 185, in <lambda>
self._caller = lambda f: f()
File "/home/fvillarroel/www/web2py/gluon/tools.py", line 2783, in f
return action(*a, **b)
File "/home/fvillarroel/www/web2py/applications/administrador/controllers/clientes.py", line 63, in clientes
table=powerTable.create()
File "/home/fvillarroel/www/web2py/applications/administrador/models/plugin_powertable.py", line 704, in plugin_powertable
PowerTable(),
File "/home/fvillarroel/www/web2py/applications/administrador/models/plugin_powertable.py", line 178, in __init__
headers[c] = sqlrows.db[t][f].label
File "/home/fvillarroel/www/web2py/gluon/dal.py", line 7136, in __getitem__
return self.__getattr__(str(key))
File "/home/fvillarroel/www/web2py/gluon/dal.py", line 7143, in __getattr__
return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'virtual'


Any idea.


Massimo Di Pierro

unread,
Sep 30, 2012, 10:00:25 PM9/30/12
to web...@googlegroups.com
I think it should be Virtual, not virtual.

FERNANDO VILLARROEL

unread,
Sep 30, 2012, 10:32:15 PM9/30/12
to web...@googlegroups.com
Dear Massimo.

My code is the following:

@auth.requires_membership('Administrador')
def clientes():


    class Virtual(object):

        @virtualsettings(label=T('Editar'))
        def edit(self):
            
            link_editar= URL(r =request,f='editablefunction',
                            args=[self.clientes.id])
            link_icono_editar= IMG(_src=URL(r=request,c='static',
                        f='images/Edit_Icon.png'),
                        _alt='Editar'
                        )
            return (A(link_icono_editar,_href= link_editar))# + str(self.clientes.id))) 

   reg=db(db.clientes).select(db.clientes.id,db.clientes.rut,db.clientes.dv,db.clientes.rsocial,
                                db.clientes.direccion,db.clientes.ciudad,db.clientes.mail,
                                db.clientes.tipo,db.clientes.fecha,db.clientes.giro,db.tarifa.nombre,
                                db.estados.nombre,db.clientes.tarifica,
            join=(db.tarifa.on(db.clientes.id_tarifa==db.tarifa.id),
                    db.estados.on(db.clientes.estado==db.estados.id),
                    db.tipos.on(db.clientes.tipo==db.tipos.id),
                    db.tarificacion.on(db.clientes.tarifica==db.tarificacion.id)),

            orderby=db.clientes.rsocial)

    powerTable = plugins.powerTable
    powerTable.datasource = reg
    .............
    .............
    table=powerTable.create()
    return dict(table=table)


I do not understand what is wrong.

--- On Sun, 9/30/12, Massimo Di Pierro <massimo....@gmail.com> wrote:

From: Massimo Di Pierro <massimo....@gmail.com>
Subject: [web2py] Re: powerTable AttributeError: 'DAL' object has no attribute 'virtual'
To: web...@googlegroups.com
Date: Sunday, September 30, 2012, 11:00 PM

I think it should be Virtual, not virtual.

On Sunday, 30 September 2012 20:11:34 UTC-5, visuallinux wrote:
Dear All.

I am trying to use PowerTable, but i am receiving the follow error:

Traceback (most recent call last):
  File "/home/fvillarroel/www/web2py/ gluon/restricted.py", line 209, in restricted
    exec ccode in environment
  File "/home/fvillarroel/www/web2py/ applications/administrador/ controllers/clientes.py", line 107, in <module>
  File "/home/fvillarroel/www/web2py/ gluon/globals.py", line 185, in <lambda>
    self._caller = lambda f: f()
  File "/home/fvillarroel/www/web2py/ gluon/tools.py", line 2783, in f
    return action(*a, **b)
  File "/home/fvillarroel/www/web2py/ applications/administrador/ controllers/clientes.py", line 63, in clientes
    table=powerTable.create()
  File "/home/fvillarroel/www/web2py/ applications/administrador/ models/plugin_powertable.py", line 704, in plugin_powertable
    PowerTable(),
  File "/home/fvillarroel/www/web2py/ applications/administrador/ models/plugin_powertable.py", line 178, in __init__
    headers[c] = sqlrows.db[t][f].label
  File "/home/fvillarroel/www/web2py/ gluon/dal.py", line 7136, in __getitem__
    return self.__getattr__(str(key))
  File "/home/fvillarroel/www/web2py/ gluon/dal.py", line 7143, in __getattr__
    return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'virtual'


Any idea.


--
 
 
 

Bruno Rocha

unread,
Oct 1, 2012, 12:04:00 AM10/1/12
to web...@googlegroups.com
Are you running new version of web2py? I guess the old style virtual fields is not working and also I have to check if the injection of virtualsettings will still work with web2py 2.0+

I will take a closer look on powertable code tomorrow to see if I can adapt it to work with the new web2py.

FERNANDO VILLARROEL

unread,
Oct 1, 2012, 9:37:12 AM10/1/12
to web...@googlegroups.com
Dear Bruno.

Yes effectively i am using the new version of web2py 2.0.8

--- On Mon, 10/1/12, Bruno Rocha <rocha...@gmail.com> wrote:

From: Bruno Rocha <rocha...@gmail.com>
Subject: Re: [web2py] Re: powerTable AttributeError: 'DAL' object has no attribute 'virtual'
To: web...@googlegroups.com
--
 
 
 

Massimo Di Pierro

unread,
Oct 1, 2012, 1:23:54 PM10/1/12
to web...@googlegroups.com
Can you please try the trunk version?

Wes Hall

unread,
Oct 1, 2012, 3:33:29 PM10/1/12
to web...@googlegroups.com
I have been having the same issue and was able to try trunk just now.

The error persists.

My working powerTable code on 1.99.3 no longer works on 2.0.9.

Massimo Di Pierro

unread,
Oct 1, 2012, 5:05:34 PM10/1/12
to web...@googlegroups.com
Are you storing a rows object in a session? Do you have DAL in modules instead of models? Do you have multiple db=DAL() statements?

tomt

unread,
Oct 2, 2012, 9:52:14 PM10/2/12
to web...@googlegroups.com
I also have been having the same issue.  I'm running web2py 2.0.9
I only have one db = DAL statement.
All of my DAL is in models/db.py.  I don't have any files in the modules directory.
I haven't specifically stored a rows object in session, although the controller does have a couple of the following statements.
if form.accepts(request.vars,session, dbio=False):

FERNANDO VILLARROEL

unread,
Oct 3, 2012, 3:26:11 PM10/3/12
to web...@googlegroups.com
Dear Bruno

Any update about powerTable + Web2py 2.0.9


--- On Mon, 10/1/12, Bruno Rocha <rocha...@gmail.com> wrote:

From: Bruno Rocha <rocha...@gmail.com>
Subject: Re: [web2py] Re: powerTable AttributeError: 'DAL' object has no attribute 'virtual'
To: web...@googlegroups.com
Date: Monday, October 1, 2012, 1:04 AM

Are you running new version of web2py? I guess the old style virtual fields is not working and also I have to check if the injection of virtualsettings will still work with web2py 2.0+

I will take a closer look on powertable code tomorrow to see if I can adapt it to work with the new web2py.

--
 
 
 

Don_X

unread,
Oct 8, 2012, 9:52:16 AM10/8/12
to web...@googlegroups.com

PowerGrid  works with the latests web2py 2+ ..... while Powertable does not

I was wondering what the real differences are between these 2 powerfull plugins

they both seems to do basically the same things ... but PowerTable looks much better  and seems to have more options ... !

the app example for powertable does not work in web2py ...

the one named :  web2py.app.skrywer_powertable.w2p 

 I tried to test it yersterday  .. but does not work !
I get the following error on 2.0.9

<type 'exceptions.AttributeError'> 'Row' object has no attribute 'product'


Version  

web2py™(2, 0, 9, datetime.datetime(2012, 10, 2, 3, 55, 58), 'dev')
PythonPython 2.7.3: /usr/bin/python

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Traceback (most recent call last
):
 
File "/home/www-data/web2py/gluon/restricted.py", line 209, in restricted
   
exec ccode in environment
  File
"/home/www-data/web2py/applications/powertable/controllers/default.py", line 80, in <module>
 
File "/home/www-data/web2py/gluon/globals.py", line 186, in <lambda>
   
self._caller = lambda f: f()
 
File "/home/www-data/web2py/applications/powertable/controllers/default.py", line 25, in index
    table
= table.create()
 
File "/home/www-data/web2py/applications/powertable/models/plugin_powertable.py", line 810, in plugin_powertable
    PowerTable
(),
 
File "/home/www-data/web2py/applications/powertable/models/plugin_powertable.py", line 214, in __init__
    _id
= record[keycolumntbl][keycolumnfld]
 
File "/home/www-data/web2py/gluon/dal.py", line 6369, in __getitem__
   
return ogetattr(self, key)
AttributeError: 'Row' object has no attribute 'product'

I was planning on  using the powertable for my soccer app ... it seems I'll have to do it with powergrid instead ...

Any news on powertable ??? ...

Bruno ... if I was half as good as you .. I would of helped you maintain this beauty ! .. i watched your vimeo cast  about it ... it is simply powerfull ...and would be very usefull to me !

Don

Massimo Di Pierro

unread,
Oct 8, 2012, 10:19:20 AM10/8/12
to web...@googlegroups.com
Please use the latest trunk or nightly built. This problem has been fixed yesterday.

Don_X

unread,
Oct 8, 2012, 11:32:09 AM10/8/12
to web...@googlegroups.com
Massimo,

the latest trunk or nightly build ... they do not run for now !

Don_X

unread,
Oct 8, 2012, 11:44:15 AM10/8/12
to web...@googlegroups.com
it runs by  bypassing the admin/default/index page ...
but F.Y.I

the powertable app example still does not run : I get the following error :


<type 'exceptions.AttributeError'> 'Row' object has no attribute 'product'


Version

web2py™(2, 1, 0, datetime.datetime(2012, 10, 8, 15, 17, 50), 'dev')
PythonPython 2.7.3: /usr/bin/python



Traceback



1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Traceback (most recent call last):
 
File "/home/www-data/web2py/gluon/restricted.py", line 209, in restricted
   
exec ccode in environment
  File
"/home/www-data/web2py/applications/powertable/controllers/default.py", line 80, in <module
>
 
File "/home/www-data/web2py/gluon/globals.py", line 187, in <lambda>
   
self._caller = lambda f: f()
 
File "/home/www-data/web2py/applications/powertable/controllers/default.py", line 25, in index
    table
= table.create()
 
File "/home/www-data/web2py/applications/powertable/models/plugin_powertable.py", line 810, in plugin_powertable
    PowerTable
(),
 
File "/home/www-data/web2py/applications/powertable/models/plugin_powertable.py", line 214, in __init__
    _id
= record[keycolumntbl][keycolumnfld]
 
File "/home/www-data/web2py/gluon/dal.py", line 6376, in __getitem__
   
return ogetattr(self, key)
AttributeError: 'Row' object has no attribute 'product'

I wish I knew how to fix this ! ... I will try though !

Massimo Di Pierro

unread,
Oct 8, 2012, 12:55:23 PM10/8/12
to web...@googlegroups.com
The error is that in plugin_powertable.py there are these lines:

                try:
                    headers[c] = sqlrows.db[t][f].label
                except KeyError:

They should be changed to

                try:
                    headers[c] = sqlrows.db[t][f].label
                except (KeyError, AttributeError):

The fact is that table[f] when f is an invalid key now raises an AttributeError, not a KeyError. That is because table[f] is the same as getattr(table,f). While we can change and revert this behavior, making table['f'] equivalent to table.f instead of vice versa resulted in a 10x improvement while extracting data from DAL.

Massimo Di Pierro

unread,
Oct 8, 2012, 12:59:00 PM10/8/12
to web...@googlegroups.com
Or better this should be:

                table = sqlrows.db[t]
                if f in table.fields:
                    headers[c] = table[f].label
                else:

Don_X

unread,
Oct 8, 2012, 1:07:46 PM10/8/12
to web...@googlegroups.com
Thank you Massimo .. but the same error persists  ... with both suggestions !

Massimo Di Pierro

unread,
Oct 8, 2012, 1:10:36 PM10/8/12
to web...@googlegroups.com
Can you show a complete traceback and a code snipped of powertable? I guess my version of powertable does not match yours or the error is now at a different line.

Don_X

unread,
Oct 8, 2012, 1:23:25 PM10/8/12
to web...@googlegroups.com

Same as above Massimo ... it gives the exact same traceback as above ...

and the lines that I have changed are from line no 177 to 185 as follows :
      elif headers=='labels':
            headers
= {}
           
for c in columns:
               
(t,f) = c.split('.')

                table
= sqlrows.db[t]
               
if f in table.fields:
                    headers
[c] = table[f].label
               
else:

                    headers
[c] = virtuallabels.get(c,capitalizefieldname(c))

 

Bruno Rocha

unread,
Oct 8, 2012, 1:33:19 PM10/8/12
to web...@googlegroups.com
Hi Don,

I will try to reproduce it here and maybe make some updates to plugin.

Can you give me a full code sample? The basic model you are using, the powerTable options etc.. (if you can put on a pastebin)

Thanks

Massimo Di Pierro

unread,
Oct 8, 2012, 1:34:28 PM10/8/12
to web...@googlegroups.com
It cannot be. The former traceback said:

  File "/home/fvillarroel/www/web2py/applications/administrador/models/plugin_powertable.py", line 178, in __init__ 
    headers[c] = sqlrows.db[t][f].label 

now this line does not exist any more. Please report the complete traceback.

Don_X

unread,
Oct 8, 2012, 1:39:09 PM10/8/12
to web...@googlegroups.com
For a more detailed report .. I have openned up the last line pertaining to the plugin_powertable.py below :



  •            
    Function argument list          

    ()

                       
    Code listing

               
               
    20.
    21.
    22.
    23.
    24.
    25.

    26.
    27.
    28.
    29.
        table.showkeycolumn = False
       
    table.extra = dict(
                           
    details={'detailscallback':URL('myfunction.load')}
                           
    )

        table = table.create()


       
    return locals()

               
    Variables

             
               
    table<Storage {'keycolumn': 'product.id', 'extra': {'...te': <function plugin_powertable at 0xa762e144>}>
    table.create<function plugin_powertable>
     
  •  

                File /home/www-data/web2py/applications/powertable/models/plugin_powertable.py in plugin_powertable at line 811
               
    code
               
    arguments
               
    variables          

    Function argument list

               

    ()

             
    Code listing
           
    806.
    807.
    808.
    809.
    810.
    811.

    812.
    813.
    814.
    815.
                                            ifunctions=str(ifunctions),
                                           
    searchcolumnjs=str(searchcolumnjs)
                                           
    )
                             
    ),
                       
    CSS,
                        PowerTable(),

                       
    )


    plugins.powerTable.create = plugin_powertable
           
    Variables

               
    global PowerTable<class '__restricted__.PowerTable'>
       

  •          

                File /home/www-data/web2py/applications/powertable/models/plugin_powertable.py in __init__ at line 215
               
    code
               
    arguments
               
    variables          


    Function argument list

               

    (self=<__restricted__.PowerTable object>)

             
    Code listing

               
               
    210.
    211.
    212.
    213.
    214.
    215.

    216.
    217.
    218.
    219.
                else:
                   
    _title = T('Record %s' % str(rc+1))

               
    #setting the id and key for every <tr> based on required keycolumn
               
    try:

  •                 _id = record[keycolumntbl][keycolumnfld]

  •            
    except KeyError:
                   
    if virtualfields:
                       
    _id = record[sqlrows.colnames[0].split('.')[0]].id
                   
    else:

               
    Variables

     
             
    record<Row {'description': 'LCD TV', 'quantity': 34, '...ter object at 0xa757f98c>, 'name': 'Television'}>
    _idundefined
    keycolumntbl'product'
    keycolumnfld'id'
       

  •             File /home/www-data/web2py/gluon/dal.py in __getitem__ at line 6376
               
    code
               
    arguments
               
    variables          

    Function argument list

               

    (self=<Row {'description': 'LCD TV', 'quantity': 34,
    '
    ...ter object at 0xa757f98c>, 'name': 'Television'}>,
    key
    ='product')

           
    Code listing
             
    6371.
    6372.
    6373.
    6374.
    6375.
    6376.

    6377.
    6378.
    6379.
    6380.
            elif m:
               
    try:
                   
    return ogetattr(self, m.group(1))[m.group(2)]
               
    except (KeyError,AttributeError,TypeError):
                   
    key = m.group(2)
            return ogetattr(self, key)


       
    def __setitem__(self, key, value):
           
    setattr(self, str(key), value)
             
    Variables

                   
    self<Row {'description': 'LCD TV', 'quantity': 34, '...ter object at 0xa757f98c>, 'name': 'Television'}>
    global ogetattr<slot wrapper '__getattribute__' of 'object' objects>
    key'product'


Don_X

unread,
Oct 8, 2012, 1:43:08 PM10/8/12
to web...@googlegroups.com

Bruno .. I am using the app example from your bitbucket

the web2py.app.skrywer_powertable.w2p 

Massimo Di Pierro

unread,
Oct 8, 2012, 1:49:09 PM10/8/12
to web...@googlegroups.com
Now the error is at a different line. The previous error has been fixed. Now it is at line 215:

            try:
                _id = record[keycolumntbl][keycolumnfld]
           
except KeyError:

as before it should be

            try:
                _id = record[keycolumntbl][keycolumnfld]
            except (KeyError, AttributeError):

Don_X

unread,
Oct 8, 2012, 1:53:27 PM10/8/12
to web...@googlegroups.com
BINGO ! - IT WORKS LIKE A CHARM MASSIMO !!! ... 

Thank you ... now  I can study this properly so I can adapt it to my app !

Massimo Di Pierro

unread,
Oct 8, 2012, 4:15:58 PM10/8/12
to web...@googlegroups.com
:-)

tomt

unread,
Oct 8, 2012, 6:53:27 PM10/8/12
to web...@googlegroups.com
Thanks to everybody for fixing this!

You might also want to make a similar change at about line 244:
 
               try:
                    field = sqlrows.db[tablename][fieldname]
#               except KeyError:
                except (KeyError,AttributeError):
                    field = None

Bruno Rocha

unread,
Oct 8, 2012, 7:42:18 PM10/8/12
to web...@googlegroups.com
Thanks, I will update the repo.

tomt

unread,
Oct 14, 2012, 11:10:17 PM10/14/12
to web...@googlegroups.com
I noticed another problem with powertable and web2py 2.0.9

When I created a new app under web2py 2.0.9 and tried to implement a powertable it exhibited some unusual behaviour. On initial callup, the powertable showed all records instead of the number specified by iDisplayLength and the columns don't show the column sorting icon. Also the column id is displayed even though table.showkeycolumn = False

Firebug showed an error in plugin_powertable/jquery.dataTables.min.js: "detailed error: TypeError: a.charCodeAt is not a function"

I discovered that if I replaced /static/js/jquery.js with version v1.7.1 from an earlier version of web2py, all the powertable problems disappeared.

Web2py 2.0.9 uses jQuery v...@1.8.0 which apparently triggers the problem with powertable.  Earlier versions of web2py used jQuery v1.7.1 which seems to work ok with powertable.

I'm wondering if I can make powertable work if I use a more recent version of datatables?  Which files from the datatables would I have to incorporate? Any suggestions?

- Tom
Message has been deleted

tomt

unread,
Oct 18, 2012, 12:06:33 AM10/18/12
to web...@googlegroups.com
After a little digging around on the web  I found out why I was powertable was generating errors with the latest web2py.

jquery version 1.8 requires jquery-ui-1.8.22

I went to http://jqueryui.com/ and downloaded legacy v1.8.24 which provided jquery-ui-1.8.24.custom.zip. This zip file included
jquery-ui-1.8.24.custom.min.js which I then copied to static/plugin_powertable/ui/js
I modified models/powertable.py to load it:
response.files.append(URL(r=request,c='static',f='plugin_powertable/ui/css/%s/jquery-ui-1.8.24.custom.css' % theme))

After taking these steps, the error messages are gone and now powertable works with no problems.

palomar

unread,
Nov 23, 2012, 2:44:01 PM11/23/12
to web...@googlegroups.com
i think 
response.files.append(URL(r=request,c='static',f='plugin_powertable/ui/css/%s/jquery-ui-1.8.24.custom.js'))
;)

Il giorno giovedì 18 ottobre 2012 06:06:33 UTC+2, tomt ha scritto:
After a little digging around on the web  I found out why I was powertable was generating errors with the latest web2py.

jquery version 1.8 requires jquery-ui-1.8.22

I went to http://jqueryui.com/ and downloaded legacy v1.8.24 which provided jquery-ui-1.8.24.custom.zip. This zip file included
jquery-ui-1.8.24.custom.min.js which I then copied to static/plugin_powertable/ui/js
I modified models/powertable.py to load it:


palomar

unread,
Nov 23, 2012, 2:50:27 PM11/23/12
to web...@googlegroups.com
Thanks for your tips but I have one more problem:
in my model I use represent to view the title instead of the ID of a linked table:

#db.acquisti.id_p.represent=lambda id, row: db.prodotti[id].nomeb

that (I think) generate this error whit powertable:
(<lambda>() takes exactly 2 arguments (1 given))

line 286:
                elif field.represent:
r = field.represent(r)

Someone can help me?
ciao ;)

tomt

unread,
Nov 23, 2012, 8:40:25 PM11/23/12
to web...@googlegroups.com
I run into the same problem.  I don't have a solution other than removing the row from the represent statement when using powertable. 
example:
db.acquisti.id_p.represent=lambda id: db.prodotti[id].nomeb
or
db.task.designer.represent = lambda value: db.staff[value].name

The problem with this is that it will then generate an error if SQLFORM.grid is used to display the same table.

palomar

unread,
Nov 24, 2012, 7:03:47 AM11/24/12
to web...@googlegroups.com
so, with web2py 2.2.1 and powertable:

db.acquisti.id_p.represent=lambda id: db.prodotti[id].nomeb          #SQLFORM.grid: doesn't work;  powertable: works
db.acquisti.id_p.represent=lambda id, row: db.prodotti[id].nomeb   #SQLFORM.grid: work;  powertable: doesn't work

Massimo, aiutaci tu! ;)
Reply all
Reply to author
Forward
0 new messages