SQLFORM.Grid - Export CSV to contain 'links' too

25 views
Skip to first unread message

James Booth

unread,
Nov 29, 2016, 10:22:29 AM11/29/16
to web2py-users
Hey guys,

I currently have the following:

db.define_table('bursary_users',
               
Field('forename', type='string', requires=IS_NOT_EMPTY()),
               
Field('surname', type='string', requires=IS_NOT_EMPTY()),
               
Field('studentId', type='string', requires=IS_NOT_EMPTY(), unique=True),
               
Field('barcode', type='string', requires=IS_NOT_EMPTY(), unique=True),
               
Field('email', type='string', requires=IS_EMAIL(), unique=True),
               
Field('is_testuser', 'boolean'),
                format
='%(studentId)s'
)


db
.define_table('bursary_entries',
               
Field('barcode', type='string', requires=[IS_IN_DB(db, 'bursary_users.barcode')]),
               
Field('entry_time', type='datetime', default=request.now, readable=True, writable=False),
               
Field('entry_location', type='string', readable=True, writable=False, requires=[IS_IN_DB(db, 'bursary_locations.bursary_location')]),
               
Field('bursary_at_time', type='string', readable=True, writable=False, requires=[IS_IN_DB(db, 'bursary_users.bursary')]),
                format
='%(barcode)s'
)


And in my controller...

grid = SQLFORM.grid(query,
                            create
=False,
                            editable
=False,
                            deletable
=False,
                            details
=False,
                            paginate
=50,
                            fields
=[
                                    db
.bursary_entries.barcode,
                                    db
.bursary_entries.entry_time,
                                    db
.bursary_entries.entry_location
                                 
],
                            links
=[
                                    dict
(header='Forename', body=lambda row: db(db.bursary_users.barcode==row.barcode).select().first().forename),
                                    dict
(header='Surname', body=lambda row: db(db.bursary_users.barcode==row.barcode).select().first().surname),
                                    dict
(header='Email', body=lambda row: db(db.bursary_users.barcode==row.barcode).select().first().email)
                                                  ])
                         

But when I try to export my query as a CSV, I only get the 'fields' (Not the links). Is there a way around this?

Kind regards,
James.
Reply all
Reply to author
Forward
0 new messages