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)
i then want to be able to set up links within the grid that sends 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 - although i have set up 'field_id=
db.MAIN.id' in the grid
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),
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