On Tue, Apr 21, 2009 at 2:12 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > This has come up before. I am not sure it is the job of web2py to do > any CSV manipulation. This is not about CSV manipulation - it is about configuring the csv library using csv library configuration methods - web2py embeds the library and default behaviors so deeply in web2py that it prevents normal configuration (uless you change gluon code). That roadblock really needs to get out of the way of applications. > If one needs a different output format it is > very easy to write a handler using SQLRows and the csv module. if csv module outputs one thing, and you overwrite (application or web2py) it makes no sense to fight csv on something csv does - making csv module settings reasonably accessible makes sense, at least on one (very surprising) occaison on web2conf REALLY got in my way, and was an unnecessary roadblock, consumed a lot of time, was frustrating and completely unnecessary - this is how I come to this. > I am > not convinced we need an API for it. No API - just access to csv module settings. I think a wrapper class would handle this well, as I tried enough other ways, and played with the csv module enough to be convinced this is the way to go. I will just do it as part of web2conf upgrades, and give you a patch. You can comment then. Yarko > > > Massimo > > On 21 Apr, 13:48, Yarko Tymciurak <yark...@gmail.com> wrote: > > Well, and that's a good (and a bad) thing... > > Note that returning str or select result calls a bunch of library things, > > and represents this as a CSV for you. (see > > gluon/sql.py/export_to_csv_file() ). > > > > While you may not have trouble with it (and most people, most of the time > > won't), also note that this uses the csv library, and with default > settings > > - which (among other things) include "\r\n" for newlines... (seehttp:// > docs.python.org/library/csv.html#csv-fmt-params > > Dialect.lineterminator) > > > > At some point we need to wrap the csv library in a class, so that web2py > > applications will be able to affect settings. > > As it is now, you can't really do that - so if defaults work, you're > great; > > if not... ugh! > > > > this is a minor thing for now, just some of the "cobwebs" in corners that > > should get cleaned up at some point... > > > > On Tue, Apr 21, 2009 at 10:59 AM, Hans < > > > > johann.scheibelho...@easytouch-edv.com> wrote: > > > > > WOW Massimo! That's almost too simple to believe it ;-) > > > > > def my_exporter(): > > > response.headers['Content-Type']='text/x-csv' > > > response.headers['Content-Disposition']='attachment; > > > filename=yourpreferredfilename.csv' > > > return str(db(...).select(...)) > > > > > On Apr 21, 4:57 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > the str(..) in str(db(...).select(...)) converts the result of the > > > > slect into CSV. > > > > > > when you call the action "http://..../my_exporter" it returns a text > > > > page containing CSV. > > > > > > If you want the browser to automatically save it in a file you may > > > > want to add two lines: > > > > > > def my_exporter(): > > > > response.headers['Content-Type']='text/x-csv' > > > > response.headers['Content-Disposition']='attachment; > > > > filename=yourpreferredfilename.csv" ' > > > > return str(db(...).select(...)) > > > > > > Massimo > > > > > > On 21 Apr, 09:38, Hans <johann.scheibelho...@easytouch-edv.com> > wrote: > > > > > > > how do I get my_exporter() into csv? is there a web2py function > which > > > > > can be called? > > > > > > > On Apr 21, 4:17 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > def my_exporter(): > > > > > > return str(db(...).select(...)) > > > > > > > > On 21 Apr, 08:52, Hans <johann.scheibelho...@easytouch-edv.com> > > > wrote: > > > > > > > > > I would like to make a controller function that does csv export > of > > > a > > > > > > > join select (similar like SQL below but into csv - temporary > table > > > ok > > > > > > > if necessary) . How can this be done in web2py? > > > > > > > > > SELECT Persons.LastName,Orders.OrderNo INTO > Persons_Order_Backup > > > FROM > > > > > > > Persons INNER JOIN Orders ON Persons.P_Id=Orders.P_Id > > > > > > > > > Thanks, > > > > > > > Hans > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@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 -~----------~----~----~----~------~----~------~--~---