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

已查看 896 次
跳至第一个未读帖子

FERNANDO VILLARROEL

未读,
2012年9月30日 21:11:282012/9/30
收件人 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

未读,
2012年9月30日 22:00:252012/9/30
收件人 web...@googlegroups.com
I think it should be Virtual, not virtual.

FERNANDO VILLARROEL

未读,
2012年9月30日 22:32:152012/9/30
收件人 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

未读,
2012年10月1日 00:04:002012/10/1
收件人 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

未读,
2012年10月1日 09:37:122012/10/1
收件人 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

未读,
2012年10月1日 13:23:542012/10/1
收件人 web...@googlegroups.com
Can you please try the trunk version?

Wes Hall

未读,
2012年10月1日 15:33:292012/10/1
收件人 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

未读,
2012年10月1日 17:05:342012/10/1
收件人 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

未读,
2012年10月2日 21:52:142012/10/2
收件人 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

未读,
2012年10月3日 15:26:112012/10/3
收件人 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

未读,
2012年10月8日 09:52:162012/10/8
收件人 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

未读,
2012年10月8日 10:19:202012/10/8
收件人 web...@googlegroups.com
Please use the latest trunk or nightly built. This problem has been fixed yesterday.

Don_X

未读,
2012年10月8日 11:32:092012/10/8
收件人 web...@googlegroups.com
Massimo,

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

Don_X

未读,
2012年10月8日 11:44:152012/10/8
收件人 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

未读,
2012年10月8日 12:55:232012/10/8
收件人 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

未读,
2012年10月8日 12:59:002012/10/8
收件人 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

未读,
2012年10月8日 13:07:462012/10/8
收件人 web...@googlegroups.com
Thank you Massimo .. but the same error persists  ... with both suggestions !

Massimo Di Pierro

未读,
2012年10月8日 13:10:362012/10/8
收件人 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

未读,
2012年10月8日 13:23:252012/10/8
收件人 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

未读,
2012年10月8日 13:33:192012/10/8
收件人 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

未读,
2012年10月8日 13:34:282012/10/8
收件人 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

未读,
2012年10月8日 13:39:092012/10/8
收件人 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

未读,
2012年10月8日 13:43:082012/10/8
收件人 web...@googlegroups.com

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

the web2py.app.skrywer_powertable.w2p 

Massimo Di Pierro

未读,
2012年10月8日 13:49:092012/10/8
收件人 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

未读,
2012年10月8日 13:53:272012/10/8
收件人 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

未读,
2012年10月8日 16:15:582012/10/8
收件人 web...@googlegroups.com
:-)

tomt

未读,
2012年10月8日 18:53:272012/10/8
收件人 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

未读,
2012年10月8日 19:42:182012/10/8
收件人 web...@googlegroups.com
Thanks, I will update the repo.

tomt

未读,
2012年10月14日 23:10:172012/10/14
收件人 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
已删除帖子

tomt

未读,
2012年10月18日 00:06:332012/10/18
收件人 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

未读,
2012年11月23日 14:44:012012/11/23
收件人 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

未读,
2012年11月23日 14:50:272012/11/23
收件人 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

未读,
2012年11月23日 20:40:252012/11/23
收件人 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

未读,
2012年11月24日 07:03:472012/11/24
收件人 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! ;)
回复全部
回复作者
转发
0 个新帖子