149
|
1 import genshi.template
|
|
2
|
153
|
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("""
|
149
|
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>
|
153
|
15 </xml>"""),
|
|
16
|
|
17 '\\h': genshi.template.MarkupTemplate("""
|
149
|
18 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
19 <html xmlns:py="http://genshi.edgewall.org/" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
20 <head>
|
|
21 <title py:content="tblname">Table Name</title>
|
|
22 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
|
23 </head>
|
|
24 <body>
|
|
25 <table py:attrs="{'id':tblname,
|
|
26 'summary':'Result set from query on table ' + tblname}">
|
|
27 <tr>
|
|
28 <th py:for="colname in colnames"
|
|
29 py:attrs="{'id':'header_' + colname.lower()}">
|
|
30 <span py:replace="colname.lower()">Column Name</span>
|
|
31 </th>
|
|
32 </tr>
|
|
33 <tr py:for="(colname, row) in zip(colnames, rows)">
|
|
34 <td py:for="itm in row" py:attrs="{'headers':'header_' + colname.lower()}">
|
|
35 <span py:replace="str(itm)">Value</span>
|
|
36 </td>
|
|
37 </tr>
|
|
38 </table>
|
|
39 </body>
|
153
|
40 </html>"""),
|
149
|
41
|
153
|
42 '\\g': genshi.template.NewTextTemplate("""
|
149
|
43 {% for (rowNum, row) in enumerate(rows) %}
|
|
44 **** Row: ${rowNum + 1}
|
|
45 {% for (colname, itm) in zip(colnames, row) %}$colname: $itm
|
153
|
46 {% end %}{% end %}"""),
|
149
|
47
|
153
|
48 '\\G': genshi.template.NewTextTemplate("""
|
149
|
49 {% for (rowNum, row) in enumerate(rows) %}
|
|
50 **** Row: ${rowNum + 1}
|
|
51 {% for (colname, itm) in zip(colnames, row) %}${colname.ljust(colnamelen)}: $itm
|
153
|
52 {% end %}{% end %}"""),
|
|
53
|
|
54 }
|