Hi all, 
I've just discovered that lazy virtual field (aka Field.Lazy) are not shown 
in a SQLFORM.grid neither implicitly (when all fields of a table are shown) 
nor explicitly (by selecting the lazy virtual field using fields).
In the latter case, the SQLFORM.grid raises an error.
The test example is:
def compute_total(row):
    print 'compute_total'
    return 0

def compute_total_lazy(row):
    print 'compute_total_lazy'
    return 1

def test():
    db.define_table('test_virtual_fields',
        Field('title','string', requires=[IS_NOT_EMPTY()]),
        Field.Virtual('total', lambda row: compute_total(row)),
        Field.Lazy('total_lazy', lambda row: compute_total_lazy(row)),
    )
    grid = SQLFORM.grid(db.test_virtual_fields)
    return response.render('default/index.html', dict(grid=grid))
while by selecting explicitly the fields with

    grid = SQLFORM.grid(db.test_virtual_fields, 
fields=[db.test_virtual_fields.title, db.test_virtual_fields.total, 
db.test_virtual_fields.total_lazy])
The following error is raised:

Traceback (most recent call last):
  File "/home/pvalleri/src/web2py/gluon/restricted.py", line 220, in restricted
    exec ccode in environment
  File 
"/home/pvalleri/src/web2py/applications/consolrocce/controllers/default.py" 
<http://127.0.0.1:8000/admin/edit/consolrocce/controllers/default.py>, line 
266, in <module>
  File "/home/pvalleri/src/web2py/gluon/globals.py", line 389, in <lambda>
    self._caller = lambda f: f()
  File 
"/home/pvalleri/src/web2py/applications/consolrocce/controllers/default.py" 
<http://127.0.0.1:8000/admin/edit/consolrocce/controllers/default.py>, line 
221, in test
    grid = SQLFORM.grid(db.test_virtual_fields, 
fields=[db.test_virtual_fields.title, db.test_virtual_fields.total, 
db.test_virtual_fields.total_lazy])
  File "/home/pvalleri/src/web2py/gluon/sqlhtml.py", line 2024, in grid
    columns = [f for f in fields if f.tablename in tablenames]
AttributeError: 'FieldMethod' object has no attribute 'tablename'



Paolo




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to