SVN: CMF/branches/jens_tools_as_utilities/CMF - converting the content_type_registry into a utility

Jens Vagelpohl <[email protected]>
Newsgroups gmane.comp.web.zope.cmf.cvs
Message-ID <[email protected]>
Log message for revision 71652:
  - converting the content_type_registry into a utility
  

Changed:
  U   CMF/branches/jens_tools_as_utilities/CMFCore/ContentTypeRegistry.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/PortalFolder.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/contenttyperegistry.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_contenttyperegistry.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml

-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/ContentTypeRegistry.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/ContentTypeRegistry.py	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/ContentTypeRegistry.py	2006-12-26 13:20:58 UTC (rev 71652)
@@ -34,6 +34,7 @@
 from permissions import ManagePortal
 from utils import _dtmldir
 from utils import getToolByName
+from utils import registerToolInterface
 
 
 class MajorMinorPredicate( SimpleItem ):
@@ -549,6 +550,7 @@
         return None
 
 InitializeClass( ContentTypeRegistry )
+registerToolInterface('content_type_registry', IContentTypeRegistry)
 
 def manage_addRegistry( self, REQUEST=None ):
     """

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/PortalFolder.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/PortalFolder.py	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/PortalFolder.py	2006-12-26 13:20:58 UTC (rev 71652)
@@ -25,6 +25,8 @@
 from Globals import InitializeClass
 from OFS.OrderSupport import OrderSupport
 from OFS.Folder import Folder
+
+from zope.component import queryUtility
 from zope.component.factory import Factory
 from zope.interface import implements
 
@@ -33,6 +35,7 @@
 from exceptions import AccessControl_Unauthorized
 from exceptions import BadRequest
 from exceptions import zExceptions_Unauthorized
+from interfaces import IContentTypeRegistry
 from interfaces import IFolderish
 from interfaces import IMutableMinimalDublinCore
 from interfaces.Folderish import Folderish as z2IFolderish
@@ -280,7 +283,7 @@
         Returns -- Bare and empty object of the appropriate type (or None, if
         we don't know what to do)
         """
-        registry = getToolByName(self, 'content_type_registry', None)
+        registry = queryUtility(IContentTypeRegistry)
         if registry is None:
             return None
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/contenttyperegistry.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/contenttyperegistry.py	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/contenttyperegistry.py	2006-12-26 13:20:58 UTC (rev 71652)
@@ -16,14 +16,17 @@
 """
 
 from zope.component import adapts
+from zope.component import getSiteManager
+from zope.component import getUtility
+from zope.component import queryUtility
 
+from Products.CMFCore.interfaces import IContentTypeRegistry
 from Products.GenericSetup.interfaces import ISetupEnviron
 from Products.GenericSetup.utils import exportObjects
 from Products.GenericSetup.utils import importObjects
 from Products.GenericSetup.utils import XMLAdapterBase
 
 from Products.CMFCore.interfaces import IContentTypeRegistry
-from Products.CMFCore.utils import getToolByName
 
 
 class ContentTypeRegistryXMLAdapter(XMLAdapterBase):
@@ -111,16 +114,16 @@
 def importContentTypeRegistry(context):
     """Import content type registry settings from an XML file.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'content_type_registry')
+    sm = getSiteManager(context.getSite())
+    tool = sm.getUtility(IContentTypeRegistry)
 
     importObjects(tool, '', context)
 
 def exportContentTypeRegistry(context):
     """Export content type registry settings as an XML file.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'content_type_registry', None)
+    sm = getSiteManager(context.getSite())
+    tool = sm.queryUtility(IContentTypeRegistry)
     if tool is None:
         logger = context.getLogger('contenttypes')
         logger.info('Nothing to export.')

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_contenttyperegistry.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_contenttyperegistry.py	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_contenttyperegistry.py	2006-12-26 13:20:58 UTC (rev 71652)
@@ -20,6 +20,9 @@
 
 from OFS.Folder import Folder
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IContentTypeRegistry
 from Products.GenericSetup.testing import BodyAdapterTestCase
 from Products.GenericSetup.tests.common import BaseRegistryTests
 from Products.GenericSetup.tests.common import DummyExportContext
@@ -155,6 +158,9 @@
         ctr = ContentTypeRegistry()
         site._setObject( ctr.getId(), ctr )
 
+        sm = getSiteManager(site)
+        sm.registerUtility(site.content_type_registry, IContentTypeRegistry)
+
         if mit_predikat:
             for (predicate_id, predicate_type, edit_args, content_type_name
                 ) in _TEST_PREDICATES:

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-12-26 13:20:58 UTC (rev 71652)
@@ -11,5 +11,8 @@
   <utility
      interface="Products.CMFCore.interfaces._tools.ICatalogTool"
      object="/portal_catalog"/>
+  <utility
+     interface="Products.CMFCore.interfaces._tools.IContentTypeRegistry"
+     object="/content_type_registry"/>
  </utilities>
 </componentregistry>

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml	2006-12-26 12:55:10 UTC (rev 71651)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/import_steps.xml	2006-12-26 13:20:58 UTC (rev 71652)
@@ -29,7 +29,7 @@
               version="20051013-01"
               handler="Products.CMFCore.exportimport.contenttyperegistry.importContentTypeRegistry"
               title="Content Type Registry">
-  <dependency step="toolset"/>
+  <dependency step="componentregistry"/>
   Import content type registry's predicates and bindings.
  </import-step>
  <import-step id="cookie_authentication"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.