[web2py] Re: csv download: how to do it

2010-04-11 Thread Yarko Tymciurak
On Apr 11, 2:39 pm, Johann Spies wrote: > With the help of firebug I determined that the problem was the link. > > I have changed the Controller to export the following: > >  link=A('Download as csv',_href=URL(r=request,f='csv',args=query)) > > And that resulted in a " Invalid request"  error. The

Re: [web2py] Re: csv download: how to do it

2010-04-11 Thread Johann Spies
With the help of firebug I determined that the problem was the link. I have changed the Controller to export the following: link=A('Download as csv',_href=URL(r=request,f='csv',args=query)) And that resulted in a " Invalid request" error. The url was: http://localhost:8000/sadec/default/csv/L

[web2py] Re: csv download: how to do it

2010-04-11 Thread Yarko Tymciurak
On Apr 11, 1:10 pm, Thadeus Burgess wrote: > If you are running local just print to stdout > > print request.vars.query. You can also use the display of these (for debuggin) on your page - see how welcome/views/generic.html accomplishes this. Then there is firebug (firefox), and - if you _really

Re: [web2py] Re: csv download: how to do it

2010-04-11 Thread Thadeus Burgess
If you are running local just print to stdout print request.vars.query. -Thadeus On Sun, Apr 11, 2010 at 12:32 PM, Johann Spies wrote: > Thanks Thaddeus.  I am not winning (yet)! > > I have now: > > > def csv(): >    import cStringIO >    s=cStringIO.StringIO() >    import gluon.conttenttyp

Re: [web2py] Re: csv download: how to do it

2010-04-11 Thread Johann Spies
Thanks Thaddeus. I am not winning (yet)! I have now: def csv(): import cStringIO s=cStringIO.StringIO() import gluon.conttenttype query = request.vars.query if not query: return None else: db(request.vars.query).select(db.sarua.ALL,limitby=(0,250)).expor

Re: [web2py] Re: csv download: how to do it

2010-04-10 Thread Thadeus Burgess
Hi Johann, Make sure to set the content-disposition header if you would like to set the filename. Also, the filename extension has to match your content-type or the browser might reject it, however that depends on the browser. -- Thadeus On Sat, 2010-04-10 at 23:56 +0200, Johann Spies wrote: >

[web2py] Re: csv download: how to do it

2010-04-10 Thread mdipierro
There are a few issues here. if the browser asks for a download name depends on the browser settings, not the server code. you can only propose a name to the browser response.headers['Content-Disposition''='attachment; filename=myfile.csv' You do not need a view unless you return a dict(). O

Re: [web2py] Re: csv download: how to do it

2010-04-10 Thread Johann Spies
On 11 April 2010 00:38, mdipierro wrote: > One thing I see is that > > > db(request.vars.query).select(db.sarua.All,limitby(1,250)).export_to_csv_file(s) > > should be > > > db(request.vars.query).select(db.sarua.ALL,limitby=(0,250)).export_to_csv_file(s) > Thanks. That was careless typing from

[web2py] Re: csv download: how to do it

2010-04-10 Thread mdipierro
One thing I see is that db(request.vars.query).select(db.sarua.All,limitby(1,250)).export_to_csv_file(s) should be db(request.vars.query).select(db.sarua.ALL,limitby=(0,250)).export_to_csv_file(s) On Apr 10, 4:56 pm, Johann Spies wrote: > I have this in my view: > > >    Download as csv

Re: [web2py] Re: csv download: how to do it

2010-04-10 Thread Johann Spies
I have this in my view: Download as csv-file And this controller: def csv(): import cStringIO s=cStringIO.StringIO() response.headers['Content-Type']='application/vnd.ms-excel' db(request.vars.query).select(db.sarua.All,limitby(1,250)).export_to_csv_file(s) return s.getvalu

Re: [web2py] Re: csv download: how to do it

2010-04-10 Thread Johann Spies
Thanks for the explanation Yarko and Vasile. I will try it out and ask more if I don't succeed. Regards Johann -- "Finally, brethren, whatsoever things are true, whatsoever things are honest, whatsoever things are just, whatsoever things are pure, whatsoever thingsare lovely, whatsoev

Re: [web2py] Re: csv download: how to do it

2010-04-10 Thread Vasile Ermicioi
db.export_to_csv_file(s) exports database to a file cStringIO is a in memory file, it is a standard python module/class http://docs.python.org/library/stringio.html and at the end you get the value from it (a big string) -- To unsubscribe, reply using "remove me" as the subject.

[web2py] Re: csv download: how to do it

2010-04-10 Thread Yarko Tymciurak
On Apr 10, 12:40 pm, Johann Spies wrote: > I do not understand the code in the manual and what I have seen on > this list about csv-downloads. > > I don't have a problem to do csv-export from the commandline in a > shell.  I just cannot figure out how the examples I referred to work > in a MVC -en