diff --git a/VERSION b/VERSION index 952a16a9..4ed77fd9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.1-alpha.2+timestamp.2013.01.15.22.22.06 +Version 2.4.1-alpha.2+timestamp.2013.01.16.09.40.52 diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 2f73fd6f..aa725f15 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -1991,6 +1991,7 @@ class SQLFORM(FORM): csv=(ExporterCSV, 'CSV'), xml=(ExporterXML, 'XML'), html=(ExporterHTML, 'HTML'), + json=(ExporterJSON, 'JSON'), tsv_with_hidden_cols= (ExporterTSV, 'TSV (Excel compatible, hidden cols)'), tsv=(ExporterTSV, 'TSV (Excel compatible)')) @@ -2938,11 +2939,10 @@ class ExporterCSV(ExportClass): def export(self): if self.rows: - return str(self.rows) + return self.rows.as_csv() else: return '' - class ExporterHTML(ExportClass): label = 'HTML' file_ext = "html" @@ -2952,18 +2952,10 @@ class ExporterHTML(ExportClass): ExportClass.__init__(self, rows) def export(self): - out = cStringIO.StringIO() - out.write('\n\n\n') if self.rows: - colnames = [a.split('.') for a in self.rows.colnames] - for row in self.rows.records: - out.write('\n') - for col in colnames: - out.write('\n') - out.write('\n') - out.write('
' + str(row[col[0]][col[1]]) + '
\n\n') - return str(out.getvalue()) - + return self.rows.xml() + else: + return '\n\n\n
\n\n' class ExporterXML(ExportClass): label = 'XML' @@ -2974,15 +2966,22 @@ class ExporterXML(ExportClass): ExportClass.__init__(self, rows) def export(self): - out = cStringIO.StringIO() - out.write('\n') if self.rows: - colnames = [a.split('.') for a in self.rows.colnames] - for row in self.rows.records: - out.write('\n') - for col in colnames: - out.write( - '<%s>' % col + str(row[col[0]][col[1]]) + '\n' % col) - out.write('\n') - out.write('') - return str(out.getvalue()) + return self.rows.as_xml() + else: + return '' + +class ExporterJSON(ExportClass): + label = 'JSON' + file_ext = "json" + content_type = "application/json" + + def __init__(self, rows): + ExportClass.__init__(self, rows) + + def export(self): + if self.rows: + return self.rows.as_json() + else: + return 'null' +