Virtual fields in SQLFORM.grid and Export to CSV

160 views
Skip to first unread message

Prasad Muley

unread,
Jan 20, 2015, 9:06:00 AM1/20/15
to web...@googlegroups.com
Hi All,

       I've some virtual fields defined in a table. These are displayed on grid using viewargs.

I've provided Export to CSV But it fails because of virtual fields.

It shows errors as 'Row' Object has no attribute 'virtual_field_name' 


app settings as below:

controllers/default.py


def person_info():

     viewargs =  viewargs = {'fields': [f for f in db.person.__dict__
                           if isinstance(db.company[f],
                                         (Field, Field.Virtual))]}
     export_csv = True
     export_classes = dict(xml=False, html=False, json=False, tsv=False,
                              tsv_with_hidden_cols=False,
                              csv_with_hidden_cols=False)  
    grid = SQLFORM.grid(query, create=False, deletable=False,
                        editable=allow_edit, maxtextlengths=maxtextlengths,
                        showbuttontext=False, csv=export_csv,
                        exportclasses=export_classes, viewargs=viewargs)    

    return dict(grid=grid)


Is it web2py bug? or 
Am I missing anything?

Prasad Muley

unread,
Jan 22, 2015, 3:42:29 AM1/22/15
to web...@googlegroups.com
This is a web2py bug. 



The expcolumns list contains all the table fields i.e including virtual fields.
for eg: [field1, field2, ..,field_N, Virtual_field_1, Virtual_field2, ..., Virtual_field_N]

selectable_columns list contain only the selectable fields. It actually removes all the virtual fields of the table.
for eg:  [ field1, field2, ... field_N]

Query is also executed without virtual_fields So rows object doesn't contain virtual_fields.


But expcolumns [which contains virtual fields ] is assigned to rows.colnames.

So It shows attribute error for virtual fields.

It should assign selectable_columns to rows.colnames

Can I create a issue for this and send the fix via pull request?
Reply all
Reply to author
Forward
0 new messages