1.1 --- a/ImprovedTableParser.py Sun Feb 19 21:42:32 2012 +0100
1.2 +++ b/ImprovedTableParser.py Sun Feb 19 23:22:47 2012 +0100
1.3 @@ -38,6 +38,11 @@
1.4
1.5 leading_number_regexp = re.compile(r"\d*")
1.6
1.7 +# Constants.
1.8 +
1.9 +up_arrow = u'\u2191'
1.10 +down_arrow = u'\u2193'
1.11 +
1.12 # Functions.
1.13
1.14 def parse(s):
1.15 @@ -419,6 +424,7 @@
1.16
1.17 columnfn, columnascending = column_types.get(columnnumber, (to_plain_text, True))
1.18 newsortcolumn = columnnumber, columnfn, columnascending
1.19 + newsortcolumn_reverse = columnnumber, columnfn, not columnascending
1.20 newlabel = columns[columnnumber][1].strip()
1.21
1.22 # Show this column in all possible places in the sorting criteria.
1.23 @@ -432,25 +438,35 @@
1.24 new_sort_columns.insert(i, newsortcolumn)
1.25 label = columns[column][1].strip()
1.26
1.27 - # Pop-up element showing the column inserted before the sort column.
1.28 + arrow = columnascending and down_arrow or up_arrow
1.29 + arrow_reverse = not columnascending and down_arrow or up_arrow
1.30 +
1.31 + sortcolumns = get_sort_column_output(new_sort_columns)
1.32 + new_sort_columns[i] = newsortcolumn_reverse
1.33 + sortcolumns_reverse = get_sort_column_output(new_sort_columns)
1.34 +
1.35 + # Columns permitting the insertion of the selected column.
1.36
1.37 if column != columnnumber and not just_had_this_column:
1.38 write(fmt.listitem(1, css_class="sortcolumn"))
1.39
1.40 + # Pop-up element showing the column inserted before the sort column.
1.41 +
1.42 write(fmt.span(1, css_class="sortcolumn-container"))
1.43 write(fmt.span(1, css_class="newsortcolumn"))
1.44 write(formatText(newlabel, request, fmt))
1.45 +
1.46 + write_sort_link(write, request, fmt, table_name, sortcolumns, arrow, "sortdirection")
1.47 + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "sortdirection")
1.48 +
1.49 write(fmt.span(0))
1.50 write(fmt.span(0))
1.51
1.52 # Link for selection of the modified sort criteria.
1.53
1.54 - write(fmt.url(1, "?%s#%s" % (
1.55 - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(new_sort_columns))),
1.56 - fmt.qualify_id(fmt.sanitize_to_id(table_name))
1.57 - )))
1.58 - write(formatText(label, request, fmt))
1.59 - write(fmt.url(0))
1.60 + write_sort_link(write, request, fmt, table_name, sortcolumns, u"%s %s" % (label, arrow), "")
1.61 +
1.62 + # Columns permitting removal or modification.
1.63
1.64 else:
1.65 write(fmt.listitem(1))
1.66 @@ -468,13 +484,12 @@
1.67
1.68 else:
1.69 just_had_this_column = True
1.70 - write(fmt.url(1, "?%s#%s" % (
1.71 - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(revised_sort_columns))),
1.72 - fmt.qualify_id(fmt.sanitize_to_id(table_name))
1.73 - ),
1.74 - css_class="removecolumn"))
1.75 - write(formatText(label, request, fmt))
1.76 - write(fmt.url(0))
1.77 + sortcolumns_revised = get_sort_column_output(revised_sort_columns)
1.78 + write_sort_link(write, request, fmt, table_name, sortcolumns_revised, u"%s %s" % (label, arrow), "removecolumn")
1.79 +
1.80 + # Alternative sort direction.
1.81 +
1.82 + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "altdirection")
1.83
1.84 write(fmt.listitem(0))
1.85
1.86 @@ -485,6 +500,13 @@
1.87 new_sort_columns = revised_sort_columns[:]
1.88 new_sort_columns.append(newsortcolumn)
1.89
1.90 + sortcolumns = get_sort_column_output(new_sort_columns)
1.91 + new_sort_columns[-1] = newsortcolumn_reverse
1.92 + sortcolumns_reverse = get_sort_column_output(new_sort_columns)
1.93 +
1.94 + arrow = columnascending and down_arrow or up_arrow
1.95 + arrow_reverse = not columnascending and down_arrow or up_arrow
1.96 +
1.97 write(fmt.listitem(1, css_class="sortcolumn", style="list-style-type: none"))
1.98
1.99 # Pop-up element showing the column inserted before the sort column.
1.100 @@ -492,15 +514,14 @@
1.101 write(fmt.span(1, css_class="sortcolumn-container"))
1.102 write(fmt.span(1, css_class="newsortcolumn"))
1.103 write(formatText(newlabel, request, fmt))
1.104 +
1.105 + write_sort_link(write, request, fmt, table_name, sortcolumns, arrow, "sortdirection")
1.106 + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "sortdirection")
1.107 +
1.108 write(fmt.span(0))
1.109 write(fmt.span(0))
1.110
1.111 - write(fmt.url(1, "?%s#%s" % (
1.112 - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(new_sort_columns))),
1.113 - fmt.qualify_id(fmt.sanitize_to_id(table_name))
1.114 - )))
1.115 - write(fmt.text(_("...")))
1.116 - write(fmt.url(0))
1.117 + write_sort_link(write, request, fmt, table_name, sortcolumns, _("..."), "")
1.118
1.119 write(fmt.listitem(0))
1.120
1.121 @@ -508,6 +529,17 @@
1.122
1.123 write(fmt.div(0))
1.124
1.125 +def write_sort_link(write, request, fmt, table_name, sortcolumns, label, css_class):
1.126 +
1.127 + "Write a link expressing sort criteria."
1.128 +
1.129 + write(fmt.url(1, "?%s#%s" % (
1.130 + wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, sortcolumns)),
1.131 + fmt.qualify_id(fmt.sanitize_to_id(table_name))
1.132 + ), css_class=css_class))
1.133 + write(formatText(label, request, fmt))
1.134 + write(fmt.url(0))
1.135 +
1.136 def get_sort_column_output(columns, start=0):
1.137
1.138 "Return the output criteria for the given 'columns' indexed from 'start'."