Modify

Opened 3 years ago

Last modified 3 years ago

#9643 new enhancement

Add default sorting to CC selector plugin

Reported by: grimmdude Owned by: hasienda
Priority: normal Component: CcSelectorPlugin
Severity: trivial Keywords: list sort
Cc: Trac Release: 0.12

Description

If there are many developers the cc list can get quite long. By simply adding the sorted() function in templates/cc_selector.html on line 31 the names will be alphabetized.

for="d in sorted(cc_developers)"

Attachments (4)

20111230_ccsel_sort_0.png (34.9 KB) - added by hasienda 3 years ago.
Cc list sort: inital state, same for the suggested sort code (does nothing here)
20111230_ccsel_sort_1.png (34.8 KB) - added by hasienda 3 years ago.
Cc list sort: key=lambda dev: dev[1]
20111230_ccsel_sort_2.png (33.8 KB) - added by hasienda 3 years ago.
Cc list sort: key=lambda dev: dev[2]
20111230_ccsel_sort_10.png (35.2 KB) - added by hasienda 3 years ago.
Cc list sort: surrogate key as suggested in my comment:1

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 years ago by anonymous

  • Type changed from defect to enhancement

comment:2 follow-up: Changed 3 years ago by hasienda

  • Keywords list sort added

I like simple solutions, nice attempt.

But my test of your code on trunk failed (no noticable change). I use a multi-purpose test environment driven by custom trac-0.13dev here.

Nevertheless I was curious enough to dig deeper into it. I made the code more explicit about what values to use:

for="d in sorted(cc_developers, key=lambda dev: dev[0])

This works since Python2.4, and I could get results for order by user(s full name) and email too. All results show the problem with a simple order on one single field. Because we display username, if user's full name isn't available, it's just too easy. We'll need an equal surrogate key to adapt to the display order, right?

Additionally IMHO the sort should be case-insensitive, because the upper letters forming a separate group looks less intuitive. So my best guess after some fiddling with this is:

for="d in sorted(cc_developers, key=lambda dev:
                 dev[1] and dev[1].lower() or dev[0].lower())

While the result is certainly not perfect in some respect (i.e. order of upper and lower letters per letter), it's an enhancement beyond the current code indeed.

Could you confirm, please? And of course, more suggestions welcome.

Changed 3 years ago by hasienda

Cc list sort: inital state, same for the suggested sort code (does nothing here)

Changed 3 years ago by hasienda

Cc list sort: key=lambda dev: dev[1]

Changed 3 years ago by hasienda

Cc list sort: key=lambda dev: dev[2]

Changed 3 years ago by hasienda

Cc list sort: surrogate key as suggested in my comment:1

comment:3 in reply to: ↑ 2 Changed 3 years ago by hasienda

Replying to hasienda:

While the result is certainly not perfect ...

Hit by a typo, please see correct link here:
the result

comment:4 Changed 3 years ago by anonymous

Thanks very much for your quick and detailed response. I don't know much about the different trac environment versions, but my original solution does work for me. I'm using Trac 0.12

Your fix works good for me as well, so it seems to be the best solution for cross version compatibility. Personally I don't use caps in any of my developer names, but I completely agree that it support for them should be added for people who do.

If you really want to get robust with it you can add a sorting header that, when clicked, reverses the sorting. I can see this being useful for very long lists. I know most users probably don't have lists that long though, but still a nice feature.

Thanks again!
-G

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.