[Zope-dev] Ordered Folder (was: Speaking of 2.6...)
Florent Guillaume
fg@nuxeo.com
Tue, 23 Apr 2002 16:05:04 +0000 (UTC)
Toby Dickenson <tdickenson@geminidataloggers.com> wrote:
> I agree with both of these two points that Jeffrey made. It is a sore
> omission from the core, but I cant see any place to hook the user
> interface that doesnt amount to "bloat" for many folders that dont
> need.
>
> Does it make sense to include an ObjectManager.manage_reorderItems
> method in the core, but leave the user interface to expansion pack
> products ?
I think the UI for reordering should be switchable, perhaps through a
new button, or a maybe a property ?
Also do we want all folders to be ordered by default ? I think yes, but
there may be backward compatibility problems.
FWIW here is the monkey patch I'm using to provide ordering
functionnality, without any UI.
Florent.
# derived from OrderFolder by Stephan Richter, iuveno AG.
from OFS.ObjectManager import ObjectManager
def get_object_position(self, id):
i = 0
for obj in self._objects:
if obj['id'] == id:
return i
i = i+1
# If the object was not found, throw an error.
raise 'ObjectNotFound', 'The object with the id "%s" does not exist.' % id
ObjectManager.get_object_position = get_object_position
def move_object_to_position(self, id, newpos):
oldpos = self.get_object_position(id)
if (newpos < 0 or newpos == oldpos or newpos >= len(self._objects)):
return 0
obj = self._objects[oldpos]
objects = list(self._objects)
del objects[oldpos]
objects.insert(newpos, obj)
self._objects = tuple(objects)
return 1
ObjectManager.move_object_to_position = move_object_to_position
def move_object_up(self, id):
newpos = self.get_object_position(id) - 1
return self.move_object_to_position(id, newpos)
ObjectManager.move_object_up = move_object_up
def move_object_down(self, id):
newpos = self.get_object_position(id) + 1
return self.move_object_to_position(id, newpos)
ObjectManager.move_object_down = move_object_down
def move_object_to_top(self, id):
newpos = 0
return self.move_object_to_position(id, newpos)
ObjectManager.move_object_to_top = move_object_to_top
def move_object_to_bottom(self, id):
newpos = len(self._objects) - 1
return self.move_object_to_position(id, newpos)
ObjectManager.move_object_to_bottom = move_object_to_bottom
def manage_renameObject(self, id, new_id, REQUEST=None):
"""Rename a particular sub-object"""
# Since OFS.CopySupport.CopyContainer::manage_renameObject uses
#_setObject manually, we have to take care of the order after it is done.
oldpos = self.get_object_position(id)
res = self._old_ordfold_manage_renameObject(id, new_id, REQUEST)
self.move_object_to_position(new_id, oldpos)
return res
ObjectManager._old_ordfold_manage_renameObject = ObjectManager.inheritedAttribute('manage_renameObject')
ObjectManager.manage_renameObject = manage_renameObject
def _setObject(self, id, object, roles=None, user=None, set_owner=1,
position=None):
res = self._old_ordfold_setObject(id, object, roles, user, set_owner)
if position is not None:
self.move_object_to_position(id, position)
# otherwise it was inserted at the end
return res
ObjectManager._old_ordfold_setObject = ObjectManager._setObject
ObjectManager._setObject = _setObject
perms = (('Manage properties', ('get_object_position',
'move_object_to_position',
'move_object_up',
'move_object_down',
'move_object_to_top',
'move_object_to_bottom')), )
ObjectManager.__ac_permissions__ = ObjectManager.__ac_permissions__ + perms
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com