Trouble with lazy virtual fields

7 views
Skip to first unread message

szimszon

unread,
Jun 28, 2010, 3:13:07 AM6/28/10
to web2py-users
After the

http://www.thadeusb.com/weblog/2009/12/31/web2py_virtualfields_as_an_orm_an_sqlalchemy_approach

webpage I made something like:
--- cut ---
db.define_table( 'web_sites',
Field( 'web_id', db.web,
label = T( 'Web config' ),
requires = IS_IN_DB( db, 'web.id', '%(name)s' ) ),
Field( 'name', 'string',
label = T( 'Name' ),
requires = [IS_NOT_EMPTY()] ),
Field( 'txt', 'text',
label = T( 'Config file' ),
requires = [IS_NOT_EMPTY()] ),
Field( 'weight', 'integer',
label = T( 'Weight' ),
requires = [IS_NOT_EMPTY()] ),
Field( 'active', 'boolean',
label = T( 'Active' ),
default = True,
),
Field( 'modified', 'boolean',
label = T( 'Modified' ),
default = True,
writable = False,
readable = False,
),
)

# computing ServerNames and ServerAliases
##########################################
class web_sites_extra():
def servername( self ):
def lzy( ):
x = 'sfjha'
return x
return lzy


db.web_sites.virtualfields.append( web_sites_extra() )
--- cut ---

In the view:
--- cut ---
{{=selected_rows[0].servername()}}

But I got:

File "gluon/sql.py", line 665, in __getattr__
return dict.__getitem__(self,key)
KeyError: 'servername'

If I only change:

class web_sites_extra():
def servername( self ):
def lzy( ):
x = 'sfjha'
return x
return lzy

to:

class web_sites_extra():
def lzy( self ):
x = 'sfjha'
return x
def servername( self ):
return self.lzy

it works.

szimszon

unread,
Jun 28, 2010, 3:35:22 AM6/28/10
to web2py-users
That's weired why is this working:

class web_sites_extra():
def servername( self ):

return self.web_sites.txt.split()

and this not:

class web_sites_extra():
def servername( self ):

r=self.web_sites.txt.split()
return self.web_sites.txt.split()

or this:

class web_sites_extra():
def servername( self ):

r="something"
return self.web_sites.txt.split()


On jún. 28, 09:13, szimszon <szims...@gmail.com> wrote:
> After the
>
> http://www.thadeusb.com/weblog/2009/12/31/web2py_virtualfields_as_an_...

szimszon

unread,
Jun 28, 2010, 2:52:06 PM6/28/10
to web2py-users
The virtualfields class is not a common python class?

szimszon

unread,
Jun 29, 2010, 2:25:21 AM6/29/10
to web2py-users
Can I help or do something to track it down?

mdipierro

unread,
Jul 26, 2010, 6:14:09 AM7/26/10
to web2py-users
I completely missed this thread. I think this is fixed now. Can
somebody try it?

szimszon

unread,
Jul 27, 2010, 2:15:23 AM7/27/10
to web2py-users
I'll if I found time for that :-)
Reply all
Reply to author
Forward
0 new messages