Add sortable columns to the dashboard and review request lists
Submitted
Updated 1 year, 4 months ago
| Christian Hammond | Reviewers | ||
| trunk | reviewboard | ||
| None | Review Board SVN | ||
Added support for sorting review requests in the dashboard and various lists (submitters, groups, all). The columns are now clickable and will cause the list to sort. Up to three columns can be taken into consideration for sorting at any given point. We update the columns when clicked as follows: * If the column is not in the existing sort list, it becomes the primary sort column and we display a large down arrow. * If the column is in the existing sort list and is the primary sort column, we reverse the order of the column and display a large up arrow. * If the column is in the sort list but is not the primary sort column, we make it the primary sort column, and we don't reverse the order. We save a cookie every time the order changes and use that next time unless a ?sort= parameter is set.
Sorted various columns and messed with each case above. Appears to work correctly.
Posted 1 year, 4 months ago (July 3rd, 2007, 12:57 a.m.)
You're not going to be happy :(
-
/trunk/reviewboard/reviews/views.py (Diff revision 4) 161 title = "All Outgoing Review Requests";
146 title = "All Outgoing Review Requests"
-
Hah
-
/trunk/reviewboard/reviews/views.py (Diff revision 4) 173 def order_by(self, *field_names):
174 return BogusQuerySet(sorted(self.list,
175 lambda a,b: self._sort_func(a, b, field_names)))
176 177 def _sort_func(self, a, b, field_list):
178 for field in field_list:
179 if field[0] == "-":
180 reverse = True
181 field = field[1:]
182 else:
183 reverse = False
184 185 try:
186 a_value = str(getattr(a, field))
187 b_value = str(getattr(b, field))
188 189 if reverse:
190 i = cmp(b_value, a_value)
191 else:
192 i = cmp(a_value, b_value)
193 194 if i != 0:
195 return i
196 except AttributeError:
197 # The field doesn't exist, so just ignore it.198 pass199 200 # They're equal, so compare the objects themselves to "sort" it out.201 return cmp(a, b)
-
Hmm. I really don't like using the BogusQuerySet for all of the views. When possible (everything except the "All Incoming Review Requests" page), we should let the database do the sort/limit. What this evaluates to is basically "SELECT * FROM blah", when what we want is "SELECT * FROM blah ORDER BY blah blah blah LIMIT blah". MySQL's finely tuned C code will be faster doing this than your python ;) When I named that object, it was in the Toejam & Earl sense of the word "Bogus", like when you eat a moldy cheeseburger.
-
/trunk/reviewboard/utils/templatetags/htmlutils.py (Diff revision 4) 43 sort_indicator = "▼"
44 new_field_name = rev_field_name
45 else:
46 sort_indicator = "▾"
47 new_field_name = self.field_name
48 except ValueError:
49 try:
50 i = sort_list.index(rev_field_name)
51 52 if i == 0:
53 sort_indicator = "▲"
54 new_field_name = self.field_name
55 else:
56 sort_indicator = "▴"
-
Can you use HTML entities for these instead?
Looks great
-
/trunk/reviewboard/utils/templatetags/htmlutils.py (Diff revision 5) 1 # vim: set fileencoding=utf-8 : -
No need for this anymore.