Opened 14 years ago
Last modified 12 months ago
#10178 new enhancement
[PATCH] Allow TracQueries to order on multiple columns
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | high | Milestone: | next-major-releases |
Component: | query system | Version: | 0.12dev |
Severity: | normal | Keywords: | patch |
Cc: | macke@…, andrew.c.martin@…, jcampbell@…, azoff@…, osimons, fabien.weyh@…, ethan.jucovy@…, phep@… | Branch: | |
Release Notes: |
ticket: Added the possibility to sort on multiple columns in the |
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Currently trac only supports ordering on a single column. I've written a patch which provides the ability to sort on more than one column.
This allows:
[[TicketQuery(max=5,order=priority|somecolumn, desc=0|1, status=open)]]
Attachments (5)
Change History (39)
by , 14 years ago
Attachment: | trac_ordering.patch added |
---|
comment:1 by , 14 years ago
Summary: | Allow TracQueries to order on multiple columns → [PATCH] Allow TracQueries to order on multiple columns |
---|
comment:2 by , 14 years ago
Component: | general → query system |
---|---|
Description: | modified (diff) |
Owner: | set to |
Priority: | normal → high |
Release Notes: | modified (diff) |
Looks very nice, thank you!
comment:3 by , 14 years ago
Some suggestions on the patch:
type(order) != type([])
should benot isinstance(order, list)
if order is not None and ...: order = [order]
but later[... for o in order]
which will fail iforder
is actuallyNone
desc = ...
- 80 cols limit (TracDev/CodingStyle)
self.order > self.desc
is likely not doing what you think it does (e.g.['a'] > [0]
isTrue
)
- tabs near the end of the patch?
comment:4 by , 14 years ago
OK, I think I've covered the suggested changes and attached the modified patch.
comment:6 by , 14 years ago
Argh. How did I manage that? Anyway…I swear this is the correct patch this time.
comment:7 by , 14 years ago
Well, I noticed that I had moved as_str()
unnecessarily, so rev 3 of this patch just drops the movement of that function. Otherwise it is the same as rev 2.
comment:8 by , 14 years ago
trac_ordering.3.patch makes 4 test cases fail. I have simplified and fixed the patch in 10178-multi-column-order-r10691.patch, but I have a bad feeling about the change. More specifically, treating the order
and desc
arguments separately feels wrong, and using a single [(field, desc), ...]
list as an order
argument would feel more natural. Except for the case where order
isn't specified, but desc
is, which means to use the default ordering but descending.
Also, the fix in get_default_columns()
is currently backward-compatible, but not necessarily the best solution.
Ideas and review welcome.
comment:9 by , 13 years ago
Cc: | added |
---|
comment:10 by , 13 years ago
How about just adding a ! or ~ prefix to the order fields to indicate that they should be reversed, i.e. something like:
[[TicketQuery(order=priority|~created|resolution)]]
I think the tilde (~) is easier to distinguish from a pipe than the exclamation mark.
Underscore or just a dash are other options.
comment:13 by , 13 years ago
Sounds good. We can keep desc
for backward compatibility, and it would only affect the first element in the order
list (i.e. for the first element in order
, sorting is descending iff the element starts with "-" or desc=1
).
comment:14 by , 13 years ago
Agree. Splitting order
and desc
is not practical. As cboos said, using minus (order=priority|-created|resolution
) is what seems most intuitive for negating the order effect.
Decisions in this ticket also has some bearing on how [query] default_order
is implemented in #10425.
comment:15 by , 13 years ago
Cc: | added |
---|
comment:16 by , 13 years ago
Cc: | added |
---|
comment:17 by , 13 years ago
Cc: | added |
---|
comment:18 by , 13 years ago
Multi-order has been integrated in patch for #10425 as requested by osimons.
Remaining work on this issue:
- Define a way for the user to select what columns to order by and if the order is to be reversed.
- Remove limitation in #10425 patch for a single rule (Query.init())
- Enable the test case for multi order.
comment:19 by , 13 years ago
Cc: | added |
---|
comment:21 by , 12 years ago
I am new to Trac so maybe I have my versioning mixed up but mine says it's 1.0.1. Does that mean this ticket should already be implemented and released? I tried this in my TracQuery but it doesn't sort by the 2nd field:
order=priority|modified
comment:22 by , 12 years ago
No, 'version' applies to version used when creating the ticket (or where bug is discovered, or as a marker of similar use). This ticket is still open, scheduled for some future non-specific milestone. To be available for you, a ticket should be 'closed' as 'fixed' and with a 'milestone' earlier or equal to the version you are using.
comment:23 by , 12 years ago
Cc: | added |
---|
comment:24 by , 11 years ago
Thanks for clarifying, osimons. I'm surprised that multi-column sorting is not yet supported. No estimate on its release, I guess?
comment:25 by , 9 years ago
Owner: | removed |
---|
comment:26 by , 9 years ago
Cc: | added |
---|
comment:27 by , 9 years ago
Keywords: | patch added |
---|
comment:28 by , 8 years ago
Is there a reason that this hasn't been included in a release 4 years after it was completed?
comment:29 by , 7 years ago
Cc: | added |
---|
comment:30 by , 3 years ago
#ping I like and need that feature (especially for sorting priority and severity) and I would like to know when this can become implemented. Thanks in advance!
comment:31 by , 13 months ago
Cc: | added |
---|
comment:32 by , 13 months ago
Cc: | removed |
---|
comment:33 by , 13 months ago
Cc: | removed |
---|
comment:34 by , 13 months ago
Cc: | added |
---|
Add multiple column ordering to trac queries