Hi guys,
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):
>>> Folder.__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.order
[u'a', u'b']
>>> f.values()
[obj1, obj2]
>>> f.is_sorted
False
>>> f.sort(reverse=True)
>>> f.order
[u'b', u'a']
>>> f.values()
[obj2, obj1]
>>> f.is_sorted()
>>> True
>>> f['c'] = obj3 # obj3.attr -> 15
>>> f.order
[u'b', u'a', u'c']
>>> f.is_sorted
False
>>> f.sort()
>>> f.order()
[u'b', u'c', u'a']
>>> f.values()
[obj2, obj3, obj1]
>>> f.is_sorted
>>> True
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
order folder.
I also miss itervalues() and iteritems(), I can also work on adding
them if you think it will be good to have.
Regards,
--
Danny Navarro | http://dannynavarro.net
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev