Based on previous code, the companies query/function would look something 
like...


    def csv_companies():
        # assumes there is a table called 'company'    with field 'name'
        query = db.company.id > 0
        companies = db(query).select(db.company.id,
                                  db.company.name,
                                  # ...
                      # the list of 'company' fields you want in your query
                      # you can join other tables and include fields from 
them here as well                  
                                  # ...
                     )

        return dict(companies=companies)





The view (csv_companies.html) would be something like...

    {{
    import cStringIO
    stream = cStringIO.StringIO()
    companies.export_to_csv_file(stream)
    response.headers['Content-Type'] = 'application/vnd.ms-excel'
    response.headers['Content-Disposition'] = 'attachment; filename="%s"' % 
your_file_name
    response.write(stream.getvalue(), escape=False)
    }}


Note it doesn't have 

    {{extend 'layout.html'}} 

as it pushes the output to a user dialogue asking if they want to open/save 
it somewhere on their machine. 
(You may want to do something different like simply write it to a directory 
or create a db entry referencing it...)



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to