2009/12/9 Thadeus Burgess <thade...@thadeusb.com>: > Is there something wrong with the following? > > results = db(db.table.field == searchvar)(db.table.field2 == > searchvar2).select() > > results.export_to_csv(outputfile, delimiter=',', quotechar='"', > qouting=csv.QOUTE_MINIMAL, represent=False) >
I would like to give the user a choice to download the results shown on the screen to a csv-file - much like appadmin do. My problem is that I still do not understand enough on how to handle the relation between the original controller, the view, and the csv-controller in this case. Once the table data (SQLTABLE) is on the screen and there is a link to download it to a csv-file, I want the user to be able to choose a filename download the data using a link in the view. In the book there is an example of a view (say default/example.csv) that looks like this: {{ import cStringIO stream=cStringIO.StringIO() sarua.export_to_csv_file(stream) response.headers['Content-Type']='application/vnd.ms-excel' response.write(stream.getvalue(), escape=False) }} But I don't know how to use it. I am also not sure how to use your example as above. I have tried this controller def csv(): import gluon.contenttype response.headers['Content-Type'] = \ gluon.contenttype.contenttype('.csv') response.vars.records.export_to_csv(response.vars.outputfile, delimiter = ',', quotechar = '"', quoting = csv.QUOTE_MINIMAL, represent = False) return And this in the view? {{extend 'layout.html'}} <a href="{{=URL(r=request,f='csv',args=request.args[0],vars=dict(records=records))}}">{{=T("export as csv file")}}</a> {{=records}} represent = False) -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.