[CMF-checkins] SVN: CMF/branches/jens_tools_as_utilities/CMF - last batch of (my) work on this branch:

Jens Vagelpohl jens at dataflake.org
Sun Jan 21 09:57:55 EST 2007


Log message for revision 72160:
  - last batch of (my) work on this branch:
    - last two tools (portal_calendar, portal_actionicons)
    - replacing getToolByName in the browser views code
  This code has one test failure in GenericSetup itself, and test failures
  in the CMFActionIcons exportimport tests.
  
  

Changed:
  U   CMF/branches/jens_tools_as_utilities/CMFActionIcons/ActionIconsTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFActionIcons/exportimport.py
  U   CMF/branches/jens_tools_as_utilities/CMFActionIcons/tests/test_exportimport.py
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/CalendarTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/browser/calendartool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/calendar_day_view.py
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/browser/document.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.txt
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/browser/metadata.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/browser/utils.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/formlib/form.py

-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFActionIcons/ActionIconsTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFActionIcons/ActionIconsTool.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFActionIcons/ActionIconsTool.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -22,10 +22,14 @@
 from AccessControl import ClassSecurityInfo
 from OFS.SimpleItem import SimpleItem
 
+from zope.interface import implements
+
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.CMFCore.Expression import Expression
+from Products.CMFCore.utils import registerToolInterface
 from Products.CMFCore.utils import UniqueObject
 
+from interfaces import IActionIconsTool
 from permissions import ManagePortal
 from permissions import View
 
@@ -35,6 +39,8 @@
 
     security = ClassSecurityInfo()
 
+    implements(IActionIconsTool)
+
     _title = None           # Use the one supplied by the provider
     _priority = 0           # All animals are equal....
     _category = 'object'
@@ -419,3 +425,5 @@
                                     )
 
 InitializeClass( ActionIconsTool )
+registerToolInterface('portal_actionicons', IActionIconsTool)
+

Modified: CMF/branches/jens_tools_as_utilities/CMFActionIcons/exportimport.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFActionIcons/exportimport.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFActionIcons/exportimport.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -22,13 +22,17 @@
 from Globals import package_home
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
-from Products.CMFCore.utils import getToolByName
+from zope.component import getSiteManager
+from zope.component import getUtility
+from zope.component import queryUtility
+
 from Products.GenericSetup.utils import CONVERTER
 from Products.GenericSetup.utils import DEFAULT
 from Products.GenericSetup.utils import ExportConfiguratorBase
 from Products.GenericSetup.utils import ImportConfiguratorBase
 from Products.GenericSetup.utils import KEY
 
+from interfaces import IActionIconsTool
 from permissions import ManagePortal
 
 _pkgdir = package_home( globals() )
@@ -40,10 +44,11 @@
 _FILENAME = 'actionicons.xml'
 
 def importActionIconsTool(context):
-    """ Import cache policy maanger settings from an XML file.
+    """ Import action icons tool settings from an XML file.
     """
     site = context.getSite()
-    ait = getToolByName(site, 'portal_actionicons', None)
+    sm = getSiteManager(site)
+    ait = sm.queryUtility(IActionIconsTool)
     if ait is None:
         return 'Action icons: No tool!'
 
@@ -89,7 +94,8 @@
     def listActionIconInfo(self):
         """ Return a list of mappings describing the action icons.
         """
-        ait = getToolByName(self._site, 'portal_actionicons')
+        sm = getSiteManager(self.getSite())
+        ait = sm.getUtility(IActionIconsTool)
         for action_icon in ait.listActionIcons():
             yield {'category': action_icon.getCategory(),
                    'action_id': action_icon.getActionId(),

Modified: CMF/branches/jens_tools_as_utilities/CMFActionIcons/tests/test_exportimport.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFActionIcons/tests/test_exportimport.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFActionIcons/tests/test_exportimport.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -18,7 +18,10 @@
 import unittest
 import Testing
 
-from Products.GenericSetup.testing import ExportImportZCMLLayer
+from zope.component import getSiteManager
+
+from Products.CMFActionIcons.interfaces import IActionIconsTool
+from Products.CMFCore.testing import ExportImportZCMLLayer
 from Products.GenericSetup.tests.common import BaseRegistryTests
 from Products.GenericSetup.tests.common import DummyExportContext
 from Products.GenericSetup.tests.common import DummyImportContext
@@ -65,6 +68,9 @@
         tool = ActionIconsTool()
         site._setObject( tool.getId(), tool )
 
+        sm = getSiteManager(site)
+        sm.registerUtility(site.portal_actionicons, IActionIconsTool)
+
         if with_icon:
             tool.addActionIcon( category=self.CATEGORY
                               , action_id=self.ACTION_ID

Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/CalendarTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/CalendarTool.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/CalendarTool.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -24,6 +24,7 @@
 from zope.interface import implements
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
+from Products.CMFCore.utils import registerToolInterface
 from Products.CMFCore.utils import UniqueObject
 
 from interfaces import ICalendarTool
@@ -353,3 +354,4 @@
         return (begin, end)
 
 InitializeClass(CalendarTool)
+registerToolInterface('portal_calendar', ICalendarTool)

Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/browser/calendartool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/browser/calendartool.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/browser/calendartool.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -21,7 +21,9 @@
 from Products.CMFDefault.browser.utils import memoize
 from Products.CMFDefault.browser.utils import ViewBase
 
+from Products.CMFCalendar.interfaces import ICalendarTool
 
+
 class CalendarView(ViewBase):
 
     """ Helper class for calendar-related templates
@@ -92,7 +94,7 @@
     def listItemInfos(self):
         """ List item infos for all event catalog records for a specific day.
         """
-        caltool = self._getTool('portal_calendar')
+        caltool = self._getToolByInterface(ICalendarTool)
         thisDay = self.viewDay()
 
         items = [ {'title': item.Title,
@@ -112,7 +114,7 @@
     def getMonthAndYear(self):
         """ Retrieve month/year tuple
         """
-        caltool = self._getTool('portal_calendar')
+        caltool = self._getToolByInterface(ICalendarTool)
         current = DateTime()
         session = None
 
@@ -146,7 +148,7 @@
     def getNextMonthLink(self, base_url, month, year):
         """ Return URL for the next month link
         """
-        caltool = self._getTool('portal_calendar')
+        caltool = self._getToolByInterface(ICalendarTool)
         nextMonthTime = caltool.getNextMonth(month, year)
 
         x = '%s?month:int=%d&year:int=%d' % ( base_url
@@ -159,7 +161,7 @@
     def getPreviousMonthLink(self, base_url, month, year):
         """ Return URL for the previous month link
         """
-        caltool = self._getTool('portal_calendar')
+        caltool = self._getToolByInterface(ICalendarTool)
         prevMonthTime = caltool.getPreviousMonth(month, year)
 
         x = '%s?month:int=%d&year:int=%d' % ( base_url

Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/calendar_day_view.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/calendar_day_view.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/calendar_day_view.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -1,9 +1,11 @@
 ##parameters=
 ##
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFDefault.utils import decode
 
-caltool = getToolByName(script, 'portal_calendar')
+caltool = getToolByInterfaceName( script
+                                , 'Products.CMFCalendar.interfaces.ICalendarTool'
+                                )
 
 options = {}
 base_url = script.absolute_url()

Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -1,9 +1,11 @@
 
 # Get the year and month that the calendar should display.
 
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
 
-caltool = getToolByName(script, 'portal_calendar')
+caltool = getToolByInterfaceName( script
+                                , 'Products.CMFCalendar.interfaces.ICalendarTool'
+                                )
 current = DateTime()
 session = None
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -35,6 +35,7 @@
 from Products.CMFCore.interfaces import ISkinsTool
 from Products.CMFCore.interfaces import ITypesTool
 from Products.CMFCore.interfaces import IURLTool
+from Products.CMFCalendar.interfaces import ICalendarTool
 from Products.CMFCalendar.testing import FunctionalLayer
 
 
@@ -131,6 +132,7 @@
         # register utilities
         sm = getSiteManager()
         sm.registerUtility(self.app.site.portal_actions, IActionsTool)
+        sm.registerUtility(self.app.site.portal_calendar, ICalendarTool)
         sm.registerUtility(self.app.site.portal_catalog, ICatalogTool)
         sm.registerUtility( self.app.site.portal_workflow
                           , IConfigurableWorkflowTool

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -30,7 +30,7 @@
 from Products.CMFCore.interfaces import IActionsTool
 from Products.CMFCore.interfaces.portal_actions \
         import ActionProvider as z2IActionProvider
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolInterface
 
 from zope.component import adapts
 from zope.component import getUtility
@@ -148,8 +148,9 @@
     def _extractOldstyleActions(self, provider_id):
         # BBB: for CMF 1.6 profiles
         fragment = self._doc.createDocumentFragment()
+        provider_iface = getToolInterface(provider_id)
+        provider = getUtility(provider_iface).__of__(self.context)
 
-        provider = getToolByName(self.context, provider_id)
         if not (IActionProvider.providedBy(provider) or
                 z2IActionProvider.isImplementedBy(provider)):
             return fragment

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_actions.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -22,13 +22,16 @@
 from Acquisition import aq_parent
 from OFS.Folder import Folder
 from OFS.OrderedFolder import OrderedFolder
+
 from zope.interface import implements
+from zope.interface import Interface
 
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.interfaces import IActionsTool
 from Products.CMFCore.interfaces.portal_actions \
     import ActionProvider as IActionProvider
 from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.utils import registerToolInterface
 from Products.GenericSetup.testing import BodyAdapterTestCase
 from Products.GenericSetup.testing import NodeAdapterTestCase
 from Products.GenericSetup.tests.common import BaseRegistryTests
@@ -199,7 +202,15 @@
 </object>
 """
 
+class IFoo(Interface):
+    """ Foo interface """
+registerToolInterface('portal_foo', IFoo)
 
+class IBar(Interface):
+    """ Bar interface """
+registerToolInterface('portal_bar', IBar)
+
+
 class DummyTool(OrderedFolder, ActionProviderBase):
 
     __implements__ = IActionProvider
@@ -362,6 +373,7 @@
 
         if foo > 0:
             site.portal_foo = DummyTool()
+            sm.registerUtility(site.portal_foo, IFoo)
 
         if foo > 1:
             site.portal_foo.addAction(id='foo',
@@ -375,6 +387,7 @@
 
         if bar > 0:
             site.portal_bar = DummyTool()
+            sm.registerUtility(site.portal_bar, IBar)
 
         if bar > 1:
             site.portal_bar.addAction(id='bar',

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -79,6 +79,13 @@
     global  _tool_interface_registry
     _tool_interface_registry[tool_id] = tool_interface
 
+security.declarePrivate('getToolInterface')
+def getToolInterface(tool_id):
+    """ Get the interface registered for a tool ID
+    """
+    global  _tool_interface_registry
+    return _tool_interface_registry.get(tool_id, None)
+
 security.declarePublic('getToolByName')
 def getToolByName(obj, name, default=_marker):
 

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/browser/document.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/browser/document.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/browser/document.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -49,12 +49,14 @@
                  'title': _(u'Change'),
                  'transform': ('validateTextFile', 'validateHTML',
                                'edit_control'),
-                 'redirect': ('portal_types', 'object/edit')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/edit')},
                 {'id': 'change_and_view',
                  'title': _(u'Change and View'),
                  'transform': ('validateTextFile', 'validateHTML',
                                'edit_control'),
-                 'redirect': ('portal_types', 'object/view')})
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/view')})
 
     #helpers
 

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -20,6 +20,7 @@
 from ZTUtils import make_query
 
 from Products.CMFCore.interfaces import IDynamicType
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFDefault.exceptions import CopyError
 from Products.CMFDefault.exceptions import zExceptions_Unauthorized
 from Products.CMFDefault.permissions import AddPortalContent
@@ -66,73 +67,86 @@
                  'title': _(u'New...'),
                  'permissions': (ViewManagementScreens, AddPortalContent),
                  'conditions': ('checkAllowedContentTypes',),
-                 'redirect': ('portal_types', 'object/new')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/new')},
                 {'id': 'items_rename',
                  'title': _(u'Rename...'),
                  'permissions': (ViewManagementScreens, AddPortalContent),
                  'conditions': ('checkItems', 'checkAllowedContentTypes'),
                  'transform': ('validateItemIds',),
-                 'redirect': ('portal_types', 'object/rename_items',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/rename_items',
                               'b_start, ids, key, reverse')},
                 {'id': 'items_cut',
                  'title': _(u'Cut'),
                  'permissions': (ViewManagementScreens,),
                  'conditions': ('checkItems',),
                  'transform': ('validateItemIds', 'cut_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_copy',
                  'title': _(u'Copy'),
                  'permissions': (ViewManagementScreens,),
                  'conditions': ('checkItems',),
                  'transform': ('validateItemIds', 'copy_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_paste',
                  'title': _(u'Paste'),
                  'permissions': (ViewManagementScreens, AddPortalContent),
                  'conditions': ('checkClipboardData',),
                  'transform': ('validateClipboardData', 'paste_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_delete',
                  'title': _(u'Delete'),
                  'permissions': (ViewManagementScreens, DeleteObjects),
                  'conditions': ('checkItems',),
                  'transform': ('validateItemIds', 'delete_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_sort',
                  'permissions': (ManageProperties,),
                  'transform': ('sort_control',),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start')},
                 {'id': 'items_up',
                  'permissions': (ManageProperties,),
                  'transform': ('validateItemIds', 'up_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_down',
                  'permissions': (ManageProperties,),
                  'transform': ('validateItemIds', 'down_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_top',
                  'permissions': (ManageProperties,),
                  'transform': ('validateItemIds', 'top_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'items_bottom',
                  'permissions': (ManageProperties,),
                  'transform': ('validateItemIds', 'bottom_control'),
-                 'redirect': ('portal_types', 'object/folderContents',
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents',
                               'b_start, key, reverse')},
                 {'id': 'set_view_filter',
                  'transform': ('set_filter_control',),
-                 'redirect': ('portal_types', 'object/folderContents')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents')},
                 {'id': 'clear_view_filter',
                  'transform': ('clear_filter_control',),
-                 'redirect': ('portal_types', 'object/folderContents')})
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/folderContents')})
 
     # helpers
 
@@ -169,7 +183,7 @@
     @memoize
     @decode
     def up_info(self):
-        mtool = self._getTool('portal_membership')
+        mtool = self._getToolByInterface(IMembershipTool)
         allowed = mtool.checkPermission(ListFolderContents, self.context,
                                         'aq_parent')
         if allowed:

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.txt
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.txt	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/browser/folder.txt	2007-01-21 14:57:53 UTC (rev 72160)
@@ -13,6 +13,7 @@
       >>> from Products.CMFCore.interfaces import IMembershipTool
       >>> from Products.CMFCore.interfaces import IPropertiesTool
       >>> from Products.CMFCore.interfaces import ITypesTool
+      >>> from Products.CMFCore.interfaces import IURLTool
       >>> sm = getSiteManager()
       >>> mtool = site._setObject('portal_membership', DummyTool())
       >>> sm.registerUtility(mtool, IMembershipTool)
@@ -21,6 +22,7 @@
       >>> ttool = site._setObject('portal_types', DummyTool())
       >>> sm.registerUtility(ttool, ITypesTool)
       >>> utool = site._setObject('portal_url', DummyTool())
+      >>> sm.registerUtility(utool, IURLTool)
 
 
   Basic functionality without security setup:

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/browser/metadata.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/browser/metadata.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/browser/metadata.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -17,6 +17,8 @@
 
 from Acquisition import aq_self
 
+from Products.CMFCore.interfaces import IDiscussionTool
+from Products.CMFCore.interfaces import IMetadataTool
 from Products.CMFDefault.exceptions import ResourceLockedError
 from Products.CMFDefault.utils import Message as _
 
@@ -33,11 +35,13 @@
     _BUTTONS = ({'id': 'change',
                  'title': _(u'Change'),
                  'transform': ('edit_control',),
-                 'redirect': ('portal_types', 'object/edit')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/edit')},
                 {'id': 'change_and_view',
                  'title': _(u'Change and View'),
                  'transform': ('edit_control',),
-                 'redirect': ('portal_types', 'object/view')})
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/view')})
 
     # interface
 
@@ -71,15 +75,18 @@
     _BUTTONS = ({'id': 'change',
                  'title': _(u'Change'),
                  'transform': ('edit_control',),
-                 'redirect': ('portal_types', 'object/metadata')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/metadata')},
                 {'id': 'change_and_edit',
                  'title': _(u'Change and Edit'),
                  'transform': ('edit_control',),
-                 'redirect': ('portal_types', 'object/edit')},
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/edit')},
                 {'id': 'change_and_view',
                  'title': _(u'Change and View'),
                  'transform': ('edit_control',),
-                 'redirect': ('portal_types', 'object/view')})
+                 'redirect': ('Products.CMFCore.interfaces.ITypesTool', 
+                              'object/view')})
 
     #helpers
 
@@ -113,7 +120,7 @@
     @memoize
     @decode
     def allowed_subjects(self):
-        mdtool = self._getTool('portal_metadata')
+        mdtool = self._getToolByInterface(IMetadataTool)
         subjects = mdtool.listAllowedSubjects(self.context)
         return tuple(subjects)
 
@@ -152,7 +159,7 @@
                      expiration_date=None, format=None, language=None,
                      rights=None, **kw):
         context = self.context
-        dtool = self._getTool('portal_discussion')
+        dtool = self._getToolByInterface(IDiscussionTool)
 
         if title is None:
             title = context.Title()

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/browser/utils.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/browser/utils.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/browser/utils.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -22,6 +22,12 @@
 from ZTUtils import Batch
 from ZTUtils import make_query
 
+from zope.component import getUtility
+
+from Products.CMFCore.interfaces import IMembershipTool
+from Products.CMFCore.interfaces import IPropertiesTool
+from Products.CMFCore.interfaces import IURLTool
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.permissions import View
 from Products.CMFDefault.utils import getBrowserCharset
@@ -74,13 +80,22 @@
         return getToolByName(self.context, name)
 
     @memoize
+    def _getToolByInterface(self, iface):
+        tool = getUtility(iface)
+        return  tool.__of__(self.context)
+
+    @memoize
+    def _getToolByInterfaceName(self, dotted_name):
+        return getToolByInterfaceName(self.context, dotted_name)
+
+    @memoize
     def _checkPermission(self, permission):
-        mtool = self._getTool('portal_membership')
+        mtool = self._getToolByInterface(IMembershipTool)
         return mtool.checkPermission(permission, self.context)
 
     @memoize
     def _getPortalURL(self):
-        utool = self._getTool('portal_url')
+        utool = self._getToolByInterface(IURLTool)
         return utool()
 
     @memoize
@@ -89,7 +104,7 @@
 
     @memoize
     def _getDefaultCharset(self):
-        ptool = self._getTool('portal_properties')
+        ptool = self._getToolByInterface(IPropertiesTool)
         return ptool.getProperty('default_charset', None)
 
     @memoize
@@ -113,8 +128,8 @@
 
     # helpers
 
-    def _setRedirect(self, provider_id, action_path, keys=''):
-        provider = self._getTool(provider_id)
+    def _setRedirect(self, provider_iface, action_path, keys=''):
+        provider = self._getToolByInterfaceName(provider_iface)
         try:
             target = provider.getActionInfo(action_path, self.context)['url']
         except ValueError:

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/formlib/form.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/formlib/form.py	2007-01-21 05:57:46 UTC (rev 72159)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/formlib/form.py	2007-01-21 14:57:53 UTC (rev 72160)
@@ -62,8 +62,8 @@
         self.request = request
         self.request.locale = getLocale(request)
 
-    def _setRedirect(self, provider_id, action_path, keys=''):
-        provider = self._getTool(provider_id)
+    def _setRedirect(self, provider_iface, action_path, keys=''):
+        provider = self._getToolByInterfaceName(provider_iface)
         try:
             target = provider.getActionInfo(action_path, self.context)['url']
         except ValueError:
@@ -145,11 +145,15 @@
 
     def handle_change_success(self, action, data):
         self._handle_success(action, data)
-        return self._setRedirect('portal_types', 'object/edit')
+        return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
+                                , 'object/edit'
+                                )
 
     def handle_change_and_view_success(self, action, data):
         self._handle_success(action, data)
-        return self._setRedirect('portal_types', 'object/view')
+        return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
+                                , 'object/view'
+                                )
 
 
 class DisplayFormBase(PageDisplayForm, ViewBase):



More information about the CMF-checkins mailing list