Add 'locateAndRegister' facility function
authorThierry Florac <tflorac@ulthar.net>
Wed, 08 Sep 2010 07:45:41 +0200
changeset 61 c9861a9a8606
parent 60 e858d602a089
child 62 c7442401b446
Add 'locateAndRegister' facility function
ztfy/utils/site.py
--- a/ztfy/utils/site.py	Sat Aug 28 02:42:28 2010 +0200
+++ b/ztfy/utils/site.py	Wed Sep 08 07:45:41 2010 +0200
@@ -18,12 +18,15 @@
 # import standard packages
 
 # import Zope3 interfaces
+from zope.app.intid.interfaces import IIntIds
 
 # import local interfaces
 from interfaces import INewSiteManagerEvent
 
 # import Zope3 packages
+from zope.app import zapi
 from zope.interface import implements
+from zope.location import locate
 
 # import local packages
 
@@ -35,3 +38,11 @@
 
     def __init__(self, obj):
         self.object = obj
+
+
+def locateAndRegister(contained, parent, key, intids=None):
+    locate(contained, parent)
+    if intids is None:
+        intids = zapi.getUtility(IIntIds)
+    intids.register(contained)
+    parent[key] = contained