import cStringIO

mystr = cStringIO.StringIO()

db.export_to_csv_file(mystr)

# set content headers

return mystr.getvalue()

-Thadeus





On Tue, Jan 19, 2010 at 5:15 PM, Miguel Goncalves
<[email protected]> wrote:
> Hi
>
> Since I am running on GAE I guess the open(...) will not work.
> Instead I am trying to add exportToCsvAll function to the appadmin.py of my
> application.
>
> I assume I have to iterate through all the tables, export them to csv into a
> string and then return the string.
>
> Question is how do I export each table? I am doing:
>
> def exportToCsvAll():
>     import gluon.contenttype
>     response.headers['Content-Type'] = gluon.contenttype.contenttype('.csv')
>     response.headers['Content-disposition'] = 'attachment;
> filename=%s_db.csv' % "MLinks"
>     res = ""
>     for table in databases['db']:
>         res = res + str(table.select())
>
>     return res
>
> the table.select() does not seem to be correct.
> Obviously table is of type gluon.contrib.qql.Table and what I need to do a
> select is a SQLDB object.
> How to I get this object?
>
> thanks
> Miguel
>
>
> On Sun, Jan 17, 2010 at 11:51 PM, mdipierro <[email protected]> wrote:
>>
>> db.export_to_csv_file(open(filename,'w'))
>>
>>
>> db.import_from_csv_file(open(filename,'r'))
>>
>>
>> On Jan 18, 1:18 am, Miguel <[email protected]> wrote:
>> > Hi
>> >
>> > Is there an easy way to export and import (.csv) all the tables of a
>> > given application at once?
>> > In the admin UI I can export tables individually but I did not find a
>> > way of exporting all at them at once.
>> >
>> > It would be really useful for testing and while working on the same
>> > application across multiple computers.
>> >
>> > Thanks
>> > -Miguel
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/web2py?hl=en.
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to