Mercurial > sqlpython
annotate sqlpython/output_templates.py @ 348:c652478be4fd
migrated \dt to gerald
author | catherine@cordelia |
---|---|
date | Fri, 24 Apr 2009 15:09:29 -0400 |
parents | c2e3223703f2 |
children |
rev | line source |
---|---|
189 | 1 import genshi.template |
2 | |
3 # To make more output formats available to sqlpython, just edit this | |
4 # file, or place a copy in your local directory and edit that. | |
5 | |
6 output_templates = { | |
7 | |
8 '\\x': genshi.template.NewTextTemplate(""" | |
9 <xml> | |
10 <${tblname}_resultset>{% for row in rows %} | |
11 <$tblname>{% for (colname, itm) in zip(colnames, row) %} | |
12 <${colname.lower()}>$itm</${colname.lower()}>{% end %} | |
13 </$tblname>{% end %} | |
14 </${tblname}_resultset> | |
15 </xml>"""), | |
16 | |
268 | 17 '\\j': genshi.template.NewTextTemplate(""" |
269 | 18 {"${tblname}": [ |
19 ${',\\n'.join(' {%s}' % ', '.join('"%s": %s' % (colname, | |
20 ((isinstance(itm,int) or isinstance(itm,float)) and '%s' or '"%s"') % str(itm) | |
21 ) for (colname, itm) in zip(colnames, row)) for row in rows)} | |
268 | 22 ] |
23 }"""), | |
24 | |
25 | |
189 | 26 '\\h': genshi.template.MarkupTemplate(""" |
27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
28 <html xmlns:py="http://genshi.edgewall.org/" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
29 <head> | |
30 <title py:content="tblname">Table Name</title> | |
31 <meta http-equiv="content-type" content="text/html;charset=utf-8" /> | |
32 </head> | |
33 <body> | |
34 <table py:attrs="{'id':tblname, | |
35 'summary':'Result set from query on table ' + tblname}"> | |
36 <tr> | |
37 <th py:for="colname in colnames" | |
38 py:attrs="{'id':'header_' + colname.lower()}"> | |
39 <span py:replace="colname.lower()">Column Name</span> | |
40 </th> | |
41 </tr> | |
42 <tr py:for="row in rows"> | |
43 <td py:for="(colname, itm) in zip(colnames, row)" py:attrs="{'headers':'header_' + colname.lower()}"> | |
44 <span py:replace="str(itm)">Value</span> | |
45 </td> | |
46 </tr> | |
47 </table> | |
48 </body> | |
49 </html>"""), | |
50 | |
51 '\\g': genshi.template.NewTextTemplate(""" | |
52 {% for (rowNum, row) in enumerate(rows) %} | |
53 **** Row: ${rowNum + 1} | |
54 {% for (colname, itm) in zip(colnames, row) %}$colname: $itm | |
55 {% end %}{% end %}"""), | |
56 | |
57 '\\G': genshi.template.NewTextTemplate(""" | |
58 {% for (rowNum, row) in enumerate(rows) %} | |
59 **** Row: ${rowNum + 1} | |
344
c2e3223703f2
finally desc works in postgres
Catherine Devlin <catherine.devlin@gmail.com>
parents:
322
diff
changeset
|
60 {% for (colname, itm) in zip(colnames, row) %}${colname.ljust(max(colnamelengths))}: $itm |
189 | 61 {% end %}{% end %}"""), |
62 | |
63 '\\i': genshi.template.NewTextTemplate("""{% for (rowNum, row) in enumerate(rows) %} | |
322
d791333902f7
handle NULLs and apostrophes in \i inserts
Catherine Devlin <catherine.devlin@gmail.com>
parents:
270
diff
changeset
|
64 INSERT INTO $tblname (${', '.join(colnames)}) VALUES (${', '.join(formattedForSql(r) for r in row)});{% end %}"""), |
189 | 65 |
66 '\\c': genshi.template.NewTextTemplate(""" | |
67 ${','.join(colnames)}{% for row in rows %} | |
68 ${','.join('"%s"' % val for val in row)}{% end %}"""), | |
69 | |
70 '\\C': genshi.template.NewTextTemplate(""" | |
71 {% for row in rows %}${','.join('"%s"' % val for val in row)}{% end %}""") | |
72 | |
73 } | |
74 | |
75 output_templates['\\s'] = output_templates['\\c'] | |
76 output_templates['\\S'] = output_templates['\\C'] |