On Tuesday, May 10, 2011 8:28:35 AM UTC-4, cyber wrote:
>
> *
>
> def export_search_results(res=None, eres=None):
> response.headers['content-type']='text/csv'
> response.headers['Content-disposition'] = 'attachment;
> filename=export.csv'
> if res is None:
> response,flash = 'None'
> else:
> return '%s\n'%';'.join('id num ves dt
> usr'.split())+'\n'.join([';'.join(map(str,[r.id, r.num, r.ves, r.dt,
> r.usr])) for r in res])
>
> if eres is None:
> *
> response,flash = 'None'
> else:
> return '%s\n'%';'.join('id num ves dt
> usr'.split())+'\n'.join([';'.join(map(str,[r.id, r.num, r.ves, r.dt,
> r.usr])) for r in eres])
>
> Then in the search view page I wrote the links like that:
> *{{for r in results:}}*
> * bla ... bla ... bla ... search results here ...*
> *{{pass}}*
> {{=A('export to CSV', _href=URL('export_search_results(results)'))}}
>
First, a controller function accessible via a URL cannot have any function
arguments (if you want to pass arguments to a URL-accessible function, they
should be passed via request.args or request.vars). Second, because
'results' is a Python object, I'm not sure you'll be able to pass it to
export_search_results() via a URL. Instead, you might consider storing
'results' in the session from the original controller function, and then
pull it from the session from within export_search_results(). You could also
simply repeat the query and re-generate the results within
export_search_results() (in that case, maybe cache the original query for
better performance).
Anthony