Worked !

On Feb 3, 5:41 pm, Anthony <[email protected]> wrote:
> On Friday, February 3, 2012 6:16:09 PM UTC-5, Omi Chiba wrote:
>
> > Do I need to rewrite this "export_csv" function completely ? or Can I
> > just add import csv and set QUOTE_ALL ?
>
> > Controller
> > --------------------------
> > def export_csv():
> >     import gluon.contenttype
> >     response.headers['Content-Type'] = \
> >         gluon.contenttype.contenttype('.csv')
> >     db = request.args[0]
> >     query = 'db.IQWAGFTY.TYPRCD!=""'
> >     response.headers['Content-disposition'] = 'attachment;
> > filename=IQWAGFTY.csv'
> >     return str(db(query,ignore_common_filters=True).select())
>
> Instead of:
>
> return str(db(query,ignore_common_filters=True).select())
>
> I think you could do something like:
>
> import csv
> import cStringIO
> rows = db(query,ignore_common_filters=True).select()
> s = cStringIO.StringIO()
> rows.export_to_csv_file(s, quoting=csv.QUOTE_ALL)
> return s.getvalue()
>
> str(rows) actually does exactly the same as the above, but the above method
> allows you to pass additional arguments to export_to_csv_file().
>
> Anthony

Reply via email to