[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ContentDirective - ContentDirective.py:1.4 meta.zcml:1.3

Jim Fulton jim@zope.com
Thu, 20 Jun 2002 16:00:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ContentDirective
In directory cvs.zope.org:/tmp/cvs-serv19918/lib/python/Zope/App/ContentDirective

Modified Files:
	ContentDirective.py meta.zcml 
Log Message:

Gary and Jim implemented most of:
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/AddMenuProposalAndEndOfZmiNamespace

A lot of clean up is needed, including:

- Implementation additional add menus, for example for services.

- Ripping out old unused implementation.





=== Zope3/lib/python/Zope/App/ContentDirective/ContentDirective.py 1.3 => 1.4 ===
 from Zope.Configuration.ConfigurationDirectiveInterfaces \
      import INonEmptyDirective
+from Zope.ComponentArchitecture import getService
 from Zope.Configuration.Exceptions import ConfigurationError
 from Zope.Configuration.Action import Action
 import Interface
-
+from Zope.App.ComponentArchitecture.ClassFactory import ClassFactory
 from Zope.App.Security.protectClass \
     import protectLikeUnto, protectName, checkPermission
 from Zope.App.ZMI.IGenericCreatorMarker import IGenericCreatorMarker
-from Zope.App.ZMI.metaConfigure import provideClass
+from Zope.Security.Proxy import ProxyFactory
+from Zope.Security.Checker import NamesChecker
 
 PublicPermission = 'Zope.Public'
 
@@ -97,36 +99,6 @@
         """Like require, but with permission_id Zope.Public"""
         return self.require(_context, PublicPermission, attributes, interface)
 
-    def factory(self, _context, permission, title, id=None, description='',
-                for_container='', creation_markers=''):
-        """Register a zmi factory for this class"""
-        if for_container:
-            for_container = tuple([_context.resolve(cls)
-                                   for cls in for_container.split()])
-        else:
-            for_container = None
-
-        if creation_markers:
-            creation_markers = tuple([_context.resolve(name)
-                                      for name in creation_markers.split()])
-        else:
-            creation_markers = (IGenericCreatorMarker,)
-
-        id = id or self.__id
-            
-        # note factories are all in one pile, services and content,
-        # so addable names must also act as if they were all in the
-        # same namespace, despite the service/content division
-        return [
-            Action(
-                discriminator = ('AddableFactory', id),
-                callable = provideClass,
-                args = ('AddableContent', id, self.__class,
-                        permission, title, description, for_container,
-                        creation_markers)
-                )
-            ]
-
 
 
     def __protectByInterface(self, interface, permission_id, r):
@@ -151,4 +123,39 @@
         "Handle empty/simple declaration."
         return ()
 
+
+    def factory(self, _context, permission, title, id=None, description=''):
+        """Register a zmi factory for this class"""
+
+        id = id or self.__id
+            
+        # note factories are all in one pile, services and content,
+        # so addable names must also act as if they were all in the
+        # same namespace, despite the service/content division
+        return [
+            Action(
+                discriminator = ('AddableFactory', id),
+                callable = provideClass,
+                args = (id, self.__class,
+                        permission, title, description)
+                )
+            ]
     
+def provideClass(id, _class, permission,
+                 title, description=''):
+    """Provide simple class setup
+
+    - create a component
+
+    - set component permission
+    """
+    factory = ClassFactory(_class)
+    if permission and (permission != 'Zope.Public'):
+        # XXX should getInterfaces be public, as below?
+        factory = ProxyFactory(factory,
+                               NamesChecker(('getInterfaces',),
+                                            __call__=permission))
+
+    getService(None, 'Factories').provideFactory(id, factory)
+
+


=== Zope3/lib/python/Zope/App/ContentDirective/meta.zcml 1.2 => 1.3 ===
       <subdirective name="allow"
                     attributes="attributes interface" />
-      <subdirective namespace="http://namespaces.zope.org/zmi"
-                    name="factory"
-                    attributes="id permission title description
-                                creation_markers" />
+      <subdirective name="factory"
+                    attributes="id permission title description" />
     </directive>
   </directives>