Ideally I would like to be able to do something like this with a repoze Folder:
>>> from repoze.folder import Folder
>>> class MyFolder(Folder):
>>> def __init__(self):
>>> self.sort_key = lambda x: self[x].attr
>>> f = MyFolder()
>>> f['a'] = obj1 # obj1.attr -> 10
>>> f['b'] = obj2 # obj2.attr -> 20
>>> f['c'] = obj3 # obj3.attr -> 15
[u'b', u'a', u'c']
[u'b', u'c', u'a']
[obj2, obj3, obj1]
These are the assumptions I made when thinking of this behavior,
correct me if they are wrong.
- I want to call sort explicitly because I think sorting every time
an object is inserted is slower than sorting after I'm finished adding
a batch objects.
- It's faster to have order stored instead of sorting dynamically
every time I ask for order.
I also suspect that for folders with lots of items a list for order
may not be the most efficient. What would be the persistent equivalent
to an efficient list with ZODB? An IOBTree?
I think I can to modify repoze.folder to support this behavior. Would
a patch for repoze.folder be welcomed? I know for complex sortings it
would be better to use repoze.catalog but I see it as the default
I also miss itervalues() and iteritems(), I can also work on adding
them if you think it will be good to have.
Danny Navarro | http://dannynavarro.net
Repoze-dev mailing list