Opened 14 years ago
Closed 9 years ago
#6904 closed New feature (wontfix)
Dictsort filter should sort case insensitive
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | mpjung@…, bmispelon@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Dictsort filter currently sorts case sensitive and thus creates sometimes two groups depending on the case of the text being sorted. The filter should use
.sort(key=str.lower)
Attachments (3)
Change History (17)
comment:1 Changed 14 years ago by
Owner: | changed from nobody to anonymous |
---|---|
Status: | new → assigned |
comment:2 Changed 14 years ago by
Has patch: | set |
---|
comment:3 Changed 14 years ago by
Owner: | changed from anonymous to mathwizard |
---|---|
Status: | assigned → new |
Changed 14 years ago by
Attachment: | dictsort.patch added |
---|
Patch against current svn patching dictsort and dictsortreversed filters
comment:4 Changed 14 years ago by
Needs documentation: | set |
---|---|
Owner: | changed from mathwizard to Michael Axiak |
Status: | new → assigned |
Triage Stage: | Unreviewed → Design decision needed |
The current patch does not work in python 2.3 and unnecessarily imports operator
. I'm uploading a new patch to address those issues.
Also, I'm not sure the benefits of this patch outweigh the backwards incompatible nature of this patch. I'm making it design decision needed until a core dev weighs in on it.
Changed 14 years ago by
Attachment: | 6904_revision7393.diff added |
---|
New patch that works in python 2.3
comment:5 Changed 14 years ago by
Whoops...there are two things that are needed for this patch:
- Tests
- For it to work sanely for non-string objects (there's no guarantee that they are strings).
I am attaching a patch that addresses these two issues.
comment:6 Changed 14 years ago by
Owner: | changed from Michael Axiak to nobody |
---|---|
Status: | assigned → new |
comment:7 follow-up: 8 Changed 14 years ago by
Thanks for vastly improving the patch. I think this feature is good way to go, cause usually when you are searching for something on a page, you don't expect, that items beginning with small letter 'a' will be somewhere down the list instead of being at the top. And the filter IS used to sort things that are being displayed on a page (it's a template filter). So from the perspective of the user this is to good way to go.
comment:8 Changed 13 years ago by
Replying to mathwizard:
you don't expect, that items beginning with small letter 'a' will be somewhere down the list instead of being at the top.
Not necessarily. For example *nix file systems are case sensitive and if I am displaying a dict of files and directories (simulating a desktop file list), then they should be sorted case sensitive - the way the filter works now.
The point is, there is a use case for both types of sorting. Perhaps a new separate filter should be created to do case incentive sorting or a switch could be provided for the existing filter to turn case-insensitive sorting on and off. However, changing the default behavior of the existing filter is a bad idea. It could create some unexpected (an undesirable) results for existing sites when they update to the latest version of Django.
comment:9 Changed 13 years ago by
Cc: | mpjung@… added |
---|---|
Patch needs improvement: | set |
Please don't just lower() the strings when sorting them. Use the collation of the locale.
http://groups.google.com/group/django-developers/browse_thread/thread/a6fa8df5787b9c32
comment:10 Changed 11 years ago by
Severity: | → Normal |
---|---|
Type: | → Bug |
I'd call this a bug, from a user perspective. Potentially backwards incompatible but probably not a big deal.
comment:11 Changed 11 years ago by
Easy pickings: | unset |
---|---|
UI/UX: | unset |
comment:12 Changed 11 years ago by
Triage Stage: | Design decision needed → Accepted |
---|---|
Type: | Bug → New feature |
I don't think case-sensitive ordering is so obviously wrong in all cases that we can just change the behavior backwards-incompatibly and force anyone who wants the current behavior to implement their own filter.
Accepting this on the basis that it would be reasonable to add something like "idictsort", since case-insensitive would frequently be preferable for strings. It would also be worth looking in more detail at whether there are any downsides to using locale collation for this new tag rather than simple .lower(), as Michael Jung suggests.
comment:13 Changed 9 years ago by
Cc: | bmispelon@… added |
---|
For what it's worth, it's already possible to do dictsort:'foo.lower'
so I'm -1 on introducing a new tag.
comment:14 Changed 9 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Agreed with bmispelon. If there's a case where foo.lower
won't work, please re-open.
the dictsort function should be like this: