Commits

Anonymous committed f0861dd

0.11-stable: Added sorting of field names by field label in custom query filter selection, column selection, grouping and textarea selection.

Previously, the order was undefined, as it depended on the order of keys in a dictionary.

Comments (0)

Files changed (2)

trac/ticket/query.py

         data['all_columns'] = query.get_all_columns()
         # Don't allow the user to remove the id column        
         data['all_columns'].remove('id')
-        data['all_textareas'] = query.get_all_textareas()
+        def field_key(name):
+            return data['labels'][name].lower()
+        data['all_columns'].sort(key=field_key)
+        data['all_textareas'] = sorted(query.get_all_textareas(),
+                                       key=field_key)
 
         add_stylesheet(req, 'common/css/report.css')
         add_script(req, 'common/js/query.js')

trac/ticket/templates/query.html

         ${wiki_to_html(context(report_resource), description)}
       </div>
 
-      <form id="query" method="post" action="${href.query()}">
+      <form id="query" method="post" action="${href.query()}"
+            py:with="field_names = sorted(fields.iterkeys(), key=lambda name: labels[name].lower())">
         <fieldset id="filters">
           <input py:if="'id' in query.constraints" type="hidden" name="id" value="${query.constraints['id']}" />
           <legend class="foldable">Filters</legend>
             <tbody>
               <tr style="height: 1px"><td colspan="4"></td></tr>
             </tbody>
-            <py:for each="field_name, field in fields.items()">
+            <py:for each="field_name in field_names" py:with="field = fields[field_name]">
               <py:for each="constraint_name, constraint in constraints.items()">
                 <tbody py:if="field_name == constraint_name"
                   py:with="multiline = field.type in ('select', 'text')">
                   <label for="add_filter">Add filter</label>&nbsp;
                   <select name="add_filter" id="add_filter">
                     <option></option>
-                    <option py:for="field_name, field in fields.items()"
+                    <option py:for="field_name in field_names" py:with="field = fields[field_name]"
                             value="$field_name"
                             disabled="${(field.type == 'radio' and
                                          field_name in constraints and
           <label for="group">Group results by</label>
           <select name="group" id="group">
             <option></option>
-            <option py:for="field_name, field in fields.items()"
-                    py:if="field.type in ('select', 'radio') or field_name in ('owner', 'reporter')"
-                    selected="${field_name == query.group or None}"
-                    value="${field_name}">${field.label}</option>
+            <py:for each="field_name in field_names" py:with="field = fields[field_name]">
+              <option py:if="field.type in ('select', 'radio') or field_name in ('owner', 'reporter')"
+                      selected="${field_name == query.group or None}"
+                      value="${field_name}">${field.label}</option>
+            </py:for>
           </select>
           <input type="checkbox" name="groupdesc" id="groupdesc"
                  checked="${query.groupdesc or None}" />