On 26 Oct 2012, at 6:40 AM, Jonathan Lundell <[email protected]> wrote:
> On 26 Oct 2012, at 2:46 AM, Niphlod <[email protected]> wrote:
>> do you serve a StringIO instance ? for 2. you may try
>> response.stream(yourcsvinstance, filename='foo.csv', attachment=True)
>
> I don't; I'm just returning a list of tuples to the Service wrapper
> (eventually I'd make it a generator, was my plan).
Here's what worked for me, for the record. In my @service.csv handler, I added
this line:
response.headers["Content-Disposition"] = "attachment;filename=%s" %
'foo.csv'
>
>>
>>
>> On Friday, October 26, 2012 1:13:17 AM UTC+2, Jonathan Lundell wrote:
>> I want to build a dataset (list of lists) in response to a user request and
>> cause a csv of that dataset to be downloaded.
>>
>> I have a working but ugly implementation that uses @service.csv. If I access
>> the URL
>>
>> http://domain.com/app/default/call/csv/foo
>>
>> ...it works OK and downloads a file named 'foo'.
>>
>> A couple of questions.
>>
>> 1. Is there a better way (considering that this is a user request, not
>> really a web service per se)?
>>
>> 2. How do I make the downloaded file, above, be named foo.csv? Maybe set
>> request.extension? (I tried call.csv in the URL, which still downloaded
>> 'foo'.)
>>
>> 3. Can I combine @auth.requires_something with @service.csv?
>>
>> Thanks!
>>
--