[Zope-Checkins] CVS: Zope/lib/python/OFS - ObjectManager.py:1.145.4.2
Casey Duncan
casey_duncan@yahoo.com
Mon, 17 Dec 2001 23:06:54 -0500
Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv11014
Modified Files:
Tag: casey-better_put_handling-branch
ObjectManager.py
Log Message:
Completed coding for manage_mkdir and tested
=== Zope/lib/python/OFS/ObjectManager.py 1.145.4.1 => 1.145.4.2 ===
meta_type = p['name']
for ob in product.objectValues():
- print ob.getId()
if ob.meta_type == 'Z Class' \
and ob._zclass_.meta_type == meta_type \
and getattr(ob._zclass_, 'isAnObjectManager', 0):
@@ -724,9 +723,15 @@
self._mkdir_meta_type = meta_type
else:
- if hasattr(aq_base(self), '_mkdir_meta_type'):
+ if hasattr(self, '_mkdir_meta_type'):
del self._mkdir_meta_type
+ if hasattr(self, '_v_mkdir_constructor'):
+ del self._v_mkdir_constructor
+
+ if hasattr(self, '_v_mkdir_permission'):
+ del self._v_mkdir_permission
+
def manage_mkdir(self, id, title='', REQUEST=None, RESPONSE=None):
"""Add the appropriate folderish object in response to a mkdir
command"""
@@ -738,19 +743,41 @@
else:
mkdir_type = 'Folder' # If we get here, something's weird
- # Get the product and find the constructor for this meta_type
- product = self.manage_addProduct[self._mkdir_meta_type]
- all = self.all_meta_types
- if callable(all):
- all = all()
- for meta_type in all:
- if meta_type['name'] == mkdir_type:
- # Get the name of the constructor
- # this is kindof a hack, but it should work
- constructor = meta_type['action'].split('/')[-1]
- # now see if we can just call it...
-
-
+ if hasattr(self, '_v_mkdir_constructor') \
+ and hasattr(self, '_v_mkdir_permission'):
+ # We already found the constructor, so use it
+ constructor = self._v_mkdir_constructor
+ permission = self._v_mkdir_permission
+ else:
+ # Do some digging to find the constructor
+ all = self.all_meta_types
+ if callable(all):
+ all = all()
+ for meta_type in all:
+ if meta_type['name'] == mkdir_type:
+ # Get the name of the constructor
+ # this is kindof a hack, but it should work
+ constructor = meta_type['action'].split('/')[-1]
+
+ if hasattr(self, constructor):
+ constructor=getattr(self, constructor)
+ else:
+ product = self.manage_addProduct[mkdir_type]
+ constructor = getattr(product, constructor)
+
+ self._v_mkdir_constructor = constructor
+ permission = meta_type.get('permission', None)
+ self._v_mkdir_permission = permission
+ break
+
+ # make sure the user has permission to create this object
+ checkPermission=getSecurityManager().checkPermission
+ if permission and not checkPermission(permission, self):
+ raise Unauthorized, 'You are not authorized to add %ss' % mkdir_type
+
+ # Try calling it
+ constructor(self, id=id, title=title, REQUEST=REQUEST)
+
def findChilds(obj,dirname=''):
""" recursive walk through the object hierarchy to