# HG changeset patch # User Paul Boddie # Date 1329682033 -3600 # Node ID ef4a711af55930c97d8d58de4fd0f7616a102d28 # Parent f40e68a2828b9ca7f2b5fc125fbf1f71c2fe0674 Added support for specifying column types in table regions without any sort criteria in order to permit sorting using the controls. The column types are defined by any explicit region declaration and are then overridden by any types specified in a region's sort criteria or in a request's sort criteria. Permitted table name definition using a table's own "tableid" attribute. diff -r f40e68a2828b -r ef4a711af559 ImprovedTableParser.py --- a/ImprovedTableParser.py Sun Feb 19 20:26:25 2012 +0100 +++ b/ImprovedTableParser.py Sun Feb 19 21:07:13 2012 +0100 @@ -514,35 +514,62 @@ table_attrs, table = parse(text) - # Override any region arguments with request parameters. + # Define the table name and an anchor attribute. table_name = attrs.get("name") if table_name: table_attrs["tableid"] = table_name + else: + table_name = table_attrs.get("tableid") - # Get sorting criteria from the region and the request. + # Get the underlying column types. + + column_types = get_column_types(get_sort_columns(attrs.get("columntypes", ""))) + + # Get sorting criteria from the region. + + region_sortcolumns = attrs.get("sortcolumns", "") + + # Update the column types from the sort criteria. + + column_types.update(get_column_types(get_sort_columns(region_sortcolumns))) - region_sortcolumns = attrs.get("sortcolumns") - sortcolumns = table_name and getQualifiedParameter(request, table_name, "sortcolumns") or region_sortcolumns + # Determine the applicable sort criteria using the request. + + if table_name: + sortcolumns = getQualifiedParameter(request, table_name, "sortcolumns") + else: + sortcolumns = None + + if sortcolumns is None: + sortcolumns = region_sortcolumns + + # Define the final sort criteria. + + sort_columns = get_sort_columns(sortcolumns) + + # Update the column types from the final sort criteria. + + column_types.update(get_column_types(sort_columns)) # Sort the rows according to the values in each of the specified columns. data_start = int(table_name and getQualifiedParameter(request, table_name, "headers") or attrs.get("headers", "1")) - if sortcolumns: + if sort_columns: headers = table[:data_start] data = table[data_start:] - # Get the sort columns using Unix sort-like notation. - - sort_columns = get_sort_columns(sortcolumns) - region_sort_columns = get_sort_columns(region_sortcolumns) + # Perform the sort and reconstruct the table. sorter = Sorter(sort_columns, request) data.sort(cmp=sorter) + table = headers + data - table = headers + data - column_types = get_column_types(region_sort_columns) + # Permit sorting because column types for sorting may have been defined. + + else: + sort_columns = [] # Write the table. @@ -551,7 +578,7 @@ for rownumber, (row_attrs, columns) in enumerate(table): write(fmt.table_row(1, row_attrs)) - sortable = sortcolumns and rownumber == data_start - 1 + sortable = column_types and rownumber == data_start - 1 for columnnumber, (column_attrs, column_text) in enumerate(columns): write(fmt.table_cell(1, column_attrs))