Hi all
I'm having some problems trying to achieve the following
I have a grid with left joins which selects a subset of entries in my
database -(query between 3 tables)
Once i get the desired result, i want to be able to set up links within the
table that then send the id from each row (MAIN table) to a seperate
function (another query between many tables).
I then want to trigger a download 'csv' file.
So far, I have managed to get this working if I use one table in the grid
(no left joins), however when i set up left joins within the grid,i get an
'AttributeError' message. Somehow, by setting up the left joins, i loose
the main id that i want to send to the seperate function.
Here's the code:
*Controller*
def vec_dyn_query():
links = [lambda ids: A('Download data
set',_href=URL("default","download_dataset.csv",args=[ids.id]))]
grid = SQLFORM.grid((db.MAIN),
field_id=db.MAIN.id,
left = [db.StudyLocation.on(db.MAIN.LocationID ==
db.StudyLocation.id), db.TAXON.on(db.MAIN.TaxonID == db.TAXON.id)],
links=links,
deletable=False, editable=False, details=False,
selectable=False, create=False, csv=False)
return locals()
def download_dataset():
main_id = request.args(0,cast=int)
dataset = db(db.MAIN.id == request.args[0]).select()
return dict(dataset=dataset)
*Views*
{{
import cStringIO
stream = cStringIO.StringIO()
dataset.export_to_csv_file(stream)
response.headers['Content-Type'] = 'text/csv'
response.write(stream.getvalue(), escape=False)
}}
Note - if i take away the 'left = [db.StudyLocation.on(db.MAIN.LocationID
== db.StudyLocation.id), db.TAXON.on(db.MAIN.TaxonID == db.TAXON.id)],'
Everything works fine
Thanks for your help in advance
Matt
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.