Commit 6b6c466a authored by Toby Dickenson's avatar Toby Dickenson

merged toby-metatype-branch

parent 104a7ae1
......@@ -44,7 +44,8 @@ class ProductContext:
def registerClass(self, instance_class=None, meta_type='',
permission=None, constructors=(),
icon=None, permissions=None, legacy=(),
visibility="Global",interfaces=_marker
visibility="Global",interfaces=_marker,
container_filter=None
):
"""Register a constructor
......@@ -88,6 +89,13 @@ class ProductContext:
interfaces -- a list of the interfaces the object supports
container_filter -- function that is called with an ObjectManager
object as the only parameter, which should return a true object
if the object is happy to be created in that container. The
filter is called before showing ObjectManager's Add list,
and before pasting (after object copy or cut), but not
before calling an object's constructor.
"""
app=self.__app
pack=self.__pack
......@@ -171,6 +179,7 @@ class ProductContext:
'visibility': visibility,
'interfaces': interfaces,
'instance': instance_class,
'container_filter': container_filter
},)
m[name]=initial
......@@ -325,3 +334,4 @@ class ProductContext:
ht=APIHelpTopic.APIHelpTopic(file, '', os.path.join(path, file))
self.registerHelpTopic(file, ht)
......@@ -12,9 +12,9 @@
##############################################################################
__doc__="""Object Manager
$Id: ObjectManager.py,v 1.149 2002/04/12 19:35:30 shane Exp $"""
$Id: ObjectManager.py,v 1.150 2002/04/15 10:15:26 htrd Exp $"""
__version__='$Revision: 1.149 $'[11:-2]
__version__='$Revision: 1.150 $'[11:-2]
import App.Management, Acquisition, Globals, CopySupport, Products
import os, App.FactoryDispatcher, re, Products
......@@ -174,49 +174,56 @@ class ObjectManager(
default__class_init__(self)
def all_meta_types(self, interfaces=None):
# A list of products registered elsewhere
external_candidates = []
# Look at _product_meta_types, if there is one
_pmt=()
if hasattr(self, '_product_meta_types'): _pmt=self._product_meta_types
elif hasattr(self, 'aq_acquire'):
try: _pmt=self.aq_acquire('_product_meta_types')
except: pass
external_candidates.extend(list(_pmt))
if interfaces is None: pmt = list(_pmt)
else:
pmt = []
for entry in pmt:
try:
eil = entry.get('interfaces',None)
if eil is not None:
for ei in eil:
for i in interfaces:
if ei is i or ei.extends(i):
pmt.append(entry)
raise BreakoutException # only append 1ce
except BreakoutException:
pass
gmt = []
# Look at all globally visible meta types.
for entry in Products.meta_types:
if ( (interfaces is not None) or (entry.get("visibility", None)=="Global") ):
external_candidates.append(entry)
# Filter the list of external candidates based on the
# specified interface constraint
if interfaces is None:
if entry.get("visibility", None) == "Global":
gmt.append(entry)
interface_constrained_meta_types = external_candidates
else:
interface_constrained_meta_types = []
for entry in external_candidates:
try:
eil = entry.get("interfaces", None)
eil = entry.get('interfaces',None)
if eil is not None:
for ei in eil:
for i in interfaces:
if ei is i or ei.extends(i):
gmt.append(entry)
interface_constrained_meta_types.append(entry)
raise BreakoutException # only append 1ce
except BreakoutException:
pass
return list(self.meta_types)+gmt+pmt
# Meta types specified by this instance are not checked against the
# interface constraint. This is as it always has been, but Im not
# sure it is correct.
interface_constrained_meta_types.extend(list(self.meta_types))
# Filter the list based on each meta-types's container_filter
meta_types = []
for entry in interface_constrained_meta_types:
container_filter = entry.get('container_filter',None)
if container_filter is None:
meta_types.append(entry)
else:
if container_filter(self):
meta_types.append(entry)
return meta_types
def _subobject_permissions(self):
return (Products.__ac_permissions__+
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment