'Export resource as CSV
@param resource: the resource to export
@note: export does not include components!
@todo: implement audit'

def csv(self, resource):

    request = current.request
    response = current.response
    if response:
        servername = ((request and ('%s_' % request.env.server_name)) or '')
        filename = ('%s%s.csv' % (servername, resource.tablename))
        from gluon.contenttype import contenttype
        response.headers['Content-Type'] = contenttype('.csv')
        response.headers['Content-disposition'] = ('attachment;    filename=%s' % filename)
    rows = resource.select(None, as_rows=True)
    return str(rows)
