[Zope] Set _allowed_meta_types on folder instances without creating a new product?
Jeff Kowalczyk
jtk@adelphia.net
Wed, 1 May 2002 18:03:15 -0400
> I told you how to define "_allowed_meta_types" on a per instance
> basis but did not check that "_allowed_meta_types" has the desired
effect.
> When your message above arrived, I tried to find a use
> of "_allowed_meta_types", but the Zope sources do not
> reference it. Where do you know about it?
I've been using it in mxmObjectManager derived product classes to limit
the Metatype list.
class PurchaseOrder(PropertyManager, mxmObjectManager.mxmObjectManager):
"A PurchaseOrder"
meta_type = 'Purchase Order'
_allowed_meta_types = ('Invoice','Item','Location','Shipment',)
It works exactly as expected, but it would be very useful to apply this
to existing folders which are specialized in purpose, but require no
special class of their own.
So I went looking into OFS ObjectManager and the mxmObjectManager
source, to see what Zope's native mechanism for this was:
mxmObjectManager.py ...
# A cleaner way to filter metatypes
# __allowed_meta_types = ('DTML Document','DTML Method')
def all_meta_types(self):
"""
Returns what meta_types can be added to the objectmanager
"""
if hasattr(self, '_allowed_meta_types'):
result = []
for metaType in Products.meta_types:
if metaType['name'] in self._allowed_meta_types:
result.append(metaType)
return result
else:
return Products.meta_types
And OFS/ObjectManager.py
def all_meta_types(self, interfaces=None):
...
def filtered_meta_types(self, user=None):
# Return a list of the types for which the user has
# adequate permission to add that type of object.
user=getSecurityManager().getUser()
meta_types=[]
if callable(self.all_meta_types):
all=self.all_meta_types()
else:
all=self.all_meta_types
for meta_type in all:
if meta_type.has_key('permission'):
if user.has_permission(meta_type['permission'],self):
meta_types.append(meta_type)
else:
meta_types.append(meta_type)
return meta_types
I'm more confused than before. Setting __all_allowed_metatypes causes a
"has key" error on the folder.