[Zope] Ordered Folders - take 2
Itamar Shtull-Trauring
itamars@ibm.net
Sun, 10 Oct 1999 13:46:30 +0200
I decided to add the ability of making an object first, as suggested by
Janko and implemented in ZClass views, to the standard Folder class, since
this should be useful for all folders, so why not? SO if I'm succesful and
DC says it doesn't break anything all our Folders will have this
capability.
I altered the main.dtml file in lib/python/OFS/ by adding these lines:
<!--#if "AUTHENTICATED_USER.has_permission('Rearrange objects',
this())"-->
<INPUT TYPE="SUBMIT" NAME="manage_first:method" VALUE="First">
<!--#/if-->
And altered the Folder class by adding a manage_first method which I ripped
from lib/python/ZClasses/Basic.py (see below for the result). Now I have
two problems:
a. Will this method actually work? I don't know enough Python, so I'm
guessing here.
b. How do I connect it to the web interface so that calling manage_first as
a method will
actually execute this function?
Here's the new Folder class:
class Folder(ObjectManager, PropertyManager, RoleManager, Collection,
SimpleItem.Item, FindSupport):
"""
The basic container object in Principia. Folders can hold almost all
other Principia objects.
"""
meta_type='Folder'
_properties=({'id':'title', 'type': 'string'},)
manage_options=(
{'label':'Contents', 'action':'manage_main'},
{'label':'View', 'action':'index_html'},
{'label':'Properties', 'action':'manage_propertiesForm'},
{'label':'Import/Export', 'action':'manage_importExportForm'},
{'label':'Security', 'action':'manage_access'},
{'label':'Undo', 'action':'manage_UndoForm'},
{'label':'Find', 'action':'manage_findFrame',
'target':'manage_main'},
)
__ac_permissions__=(('Rearrange objects', ('manage_first',)),)
def manage_first(self, selected=[], REQUEST=None):
"""Make some objects first"""
objects=self._objects
if not selected:
message="No objects were selected to be made first."
elif len(selected)==len(objects):
message="Making all objects first has no effect."
else:
objects=self._objects
objects=tuple(
filter(lambda object, selected=selected:
object in selected,
objects)
+
filter(lambda object, selected=selected:
object not in selected,
objects)
)
self.setClassAttr('_objects', objects)
message="Objects were rearranged as requested."
if REQUEST is not None:
return self.manage(
self, REQUEST, manage_tabs_message=message)
--
Itamar - itamars@ibm.net
---------------------------o----------------------------------------------o
Perl/Gimp Greeting Cards | Trust? Ha! The US dollar is backed by ICBMs! |
http://www.sealingwax.com | --Anonymous Coward, Slashdot |