1.1 --- a/ImprovedTableParser.py Fri Jul 13 01:13:08 2012 +0200
1.2 +++ b/ImprovedTableParser.py Mon Jul 16 00:36:12 2012 +0200
1.3 @@ -401,17 +401,20 @@
1.4
1.5 return 0
1.6
1.7 -def write_sort_control(request, columnnumber, columns, sort_columns, column_types, table_name, start=0):
1.8 +def write_sort_control(request, columnnumber, columns, sort_columns, column_types, table_name, start=0, write=None):
1.9
1.10 """
1.11 Using the 'request', write a sort control for the given 'columnnumber' in
1.12 the collection of 'columns', using the existing 'sort_columns' and
1.13 'column_types' to construct labels and links that modify the sort criteria,
1.14 and using the given 'table_name' to parameterise the links.
1.15 +
1.16 + If the 'write' parameter is specified, use it to write output; otherwise,
1.17 + write output using the request.
1.18 """
1.19
1.20 fmt = request.formatter
1.21 - write = request.write
1.22 + write = write or request.write
1.23 _ = request.getText
1.24
1.25 write(fmt.div(1, css_class="sortcolumns"))
1.26 @@ -556,11 +559,14 @@
1.27
1.28 # Common formatting functions.
1.29
1.30 -def formatTable(text, request, fmt, attrs=None):
1.31 +def formatTable(text, request, fmt, attrs=None, write=None):
1.32
1.33 """
1.34 Format the given 'text' using the specified 'request' and formatter 'fmt'.
1.35 The optional 'attrs' can be used to control the presentation of the table.
1.36 +
1.37 + If the 'write' parameter is specified, use it to write output; otherwise,
1.38 + write output using the request.
1.39 """
1.40
1.41 # Parse the table region.
1.42 @@ -625,7 +631,7 @@
1.43
1.44 # Write the table.
1.45
1.46 - write = request.write
1.47 + write = write or request.write
1.48 write(fmt.table(1, table_attrs))
1.49
1.50 for rownumber, (row_attrs, columns) in enumerate(table):
1.51 @@ -668,7 +674,7 @@
1.52 # Add sorting controls, if appropriate.
1.53
1.54 if sortable_heading:
1.55 - write_sort_control(request, columnnumber, columns, sort_columns, column_types, table_name)
1.56 + write_sort_control(request, columnnumber, columns, sort_columns, column_types, table_name, write=write)
1.57 write(fmt.div(0))
1.58
1.59 write(fmt.table_cell(0))
1.60 @@ -677,4 +683,27 @@
1.61
1.62 write(fmt.table(0))
1.63
1.64 +def formatTableForOutputType(text, request, mimetype, attrs=None, write=None):
1.65 +
1.66 + """
1.67 + Format the given 'text' using the specified 'request' for the given output
1.68 + 'mimetype'.
1.69 +
1.70 + The optional 'attrs' can be used to control the presentation of the table.
1.71 +
1.72 + If the 'write' parameter is specified, use it to write output; otherwise,
1.73 + write output using the request.
1.74 + """
1.75 +
1.76 + write = write or request.write
1.77 +
1.78 + if mimetype == "text/html":
1.79 + write('<html>')
1.80 + write('<body>')
1.81 + fmt = request.html_formatter
1.82 + fmt.setPage(request.page)
1.83 + formatTable(text, request, fmt, attrs, write)
1.84 + write('</body>')
1.85 + write('</html>')
1.86 +
1.87 # vim: tabstop=4 expandtab shiftwidth=4