ignore_case patch for dtml-in and dtml-tree
Created by .
Last modified on 2003/08/05.
Ever noticed how Zope uses the standard python sort function so that uppercase strings get put before lower case strings?
If you're not sure what I'm talking about add in two folders id: AFolder and aFolder.... you would think they would
be next to each other, but they aren't. Because "A" comes before "a", in fact before any lower case letter.
To me this is confusing, and some users agree. So I patched my source, so that
you can use add the variable ignore_case to the dtml-in and tree tags. You could even make this the default behaviour
Example:
<dtml-tree branches_expr="objectValues([..])" sort=title>
|
Danae and Andy
|
|
Images
|
|
Install Docs
|
|
danae
|
|
iguana
|
<dtml-tree branches_expr="objectValues([..])" sort=title ignore_case>
|
danae
|
|
Danae and Andy
|
|
iguana
|
|
Images
|
|
Install Docs
|
Patches:
/lib/python/DocumentTemplate/DT-In.py
Old Line 418: reverse=1, case_sensitive=1)
New Line 418: reverse=1, case_sensitive=1, ignore_case=1)
* I'm not sure what this case_sensitive option is, its not documented or used, perhaps someone was trying to do the same thing?
Old Line 747: s.sort()
New Line 747-8: if self.args.has_key('ignore_case'): s.sort(lambda x, y: cmp(lower(x[0]), lower(y[0])))
else: s.sort()
/lib/python/TreeDisplay/TreeTag.py
Old Line 119: urlparam=None)
New Line 119: urlparam=None, ignore_case=1)
Old Line 351: items.sort()
New Line 351-2: if have_arg('ignore_case'): items.sort(lambda x, y: cmp(lower(x[0]), lower(y[0])))
else: items.sort()
Note: to be confirmed when I can run a diff on a Linux box.
Pretty simple eh? This isn't meant to solve all the millions of different sorting problems out there (punctation, Catalog etc.) just make a simple
management interface nicer. BTW if you change "if have_arg(..." to "if not have_arg(...", then case insensitive sorting becomes the norm, not the exception.
Tested Zopes:
- Zope 2.2.4
- On title and id fields