[CMF-checkins] SVN: CMF/trunk/CMF - replaced _getTool* by
getUtility calls
Yvo Schubbe
y.2007- at wcm-solutions.de
Thu Mar 8 03:03:18 EST 2007
Log message for revision 73055:
- replaced _getTool* by getUtility calls
Changed:
U CMF/trunk/CMFCalendar/browser/calendartool.py
U CMF/trunk/CMFDefault/browser/folder.py
U CMF/trunk/CMFDefault/browser/metadata.py
U CMF/trunk/CMFDefault/browser/utils.py
U CMF/trunk/CMFDefault/formlib/form.py
-=-
Modified: CMF/trunk/CMFCalendar/browser/calendartool.py
===================================================================
--- CMF/trunk/CMFCalendar/browser/calendartool.py 2007-03-08 05:33:18 UTC (rev 73054)
+++ CMF/trunk/CMFCalendar/browser/calendartool.py 2007-03-08 08:03:18 UTC (rev 73055)
@@ -16,6 +16,7 @@
"""
from DateTime.DateTime import DateTime
+from zope.component import getUtility
from Products.CMFDefault.browser.utils import decode
from Products.CMFDefault.browser.utils import memoize
@@ -94,7 +95,7 @@
def listItemInfos(self):
""" List item infos for all event catalog records for a specific day.
"""
- caltool = self._getToolByInterface(ICalendarTool)
+ caltool = getUtility(ICalendarTool)
thisDay = self.viewDay()
items = [ {'title': item.Title,
@@ -114,7 +115,7 @@
def getMonthAndYear(self):
""" Retrieve month/year tuple
"""
- caltool = self._getToolByInterface(ICalendarTool)
+ caltool = getUtility(ICalendarTool)
current = DateTime()
session = None
@@ -148,7 +149,7 @@
def getNextMonthLink(self, base_url, month, year):
""" Return URL for the next month link
"""
- caltool = self._getToolByInterface(ICalendarTool)
+ caltool = getUtility(ICalendarTool)
nextMonthTime = caltool.getNextMonth(month, year)
x = '%s?month:int=%d&year:int=%d' % ( base_url
@@ -161,7 +162,7 @@
def getPreviousMonthLink(self, base_url, month, year):
""" Return URL for the previous month link
"""
- caltool = self._getToolByInterface(ICalendarTool)
+ caltool = getUtility(ICalendarTool)
prevMonthTime = caltool.getPreviousMonth(month, year)
x = '%s?month:int=%d&year:int=%d' % ( base_url
Modified: CMF/trunk/CMFDefault/browser/folder.py
===================================================================
--- CMF/trunk/CMFDefault/browser/folder.py 2007-03-08 05:33:18 UTC (rev 73054)
+++ CMF/trunk/CMFDefault/browser/folder.py 2007-03-08 08:03:18 UTC (rev 73055)
@@ -16,11 +16,13 @@
"""
from DocumentTemplate import sequence
+from zope.component import getUtility
from ZTUtils import LazyFilter
from ZTUtils import make_query
from Products.CMFCore.interfaces import IDynamicType
from Products.CMFCore.interfaces import IMembershipTool
+from Products.CMFCore.interfaces import ITypesTool
from Products.CMFDefault.exceptions import CopyError
from Products.CMFDefault.exceptions import zExceptions_Unauthorized
from Products.CMFDefault.permissions import AddPortalContent
@@ -67,86 +69,73 @@
'title': _(u'New...'),
'permissions': (ViewManagementScreens, AddPortalContent),
'conditions': ('checkAllowedContentTypes',),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/new')},
+ 'redirect': (ITypesTool, 'object/new')},
{'id': 'items_rename',
'title': _(u'Rename...'),
'permissions': (ViewManagementScreens, AddPortalContent),
'conditions': ('checkItems', 'checkAllowedContentTypes'),
'transform': ('validateItemIds',),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/rename_items',
+ 'redirect': (ITypesTool, 'object/rename_items',
'b_start, ids, key, reverse')},
{'id': 'items_cut',
'title': _(u'Cut'),
'permissions': (ViewManagementScreens,),
'conditions': ('checkItems',),
'transform': ('validateItemIds', 'cut_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_copy',
'title': _(u'Copy'),
'permissions': (ViewManagementScreens,),
'conditions': ('checkItems',),
'transform': ('validateItemIds', 'copy_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_paste',
'title': _(u'Paste'),
'permissions': (ViewManagementScreens, AddPortalContent),
'conditions': ('checkClipboardData',),
'transform': ('validateClipboardData', 'paste_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_delete',
'title': _(u'Delete'),
'permissions': (ViewManagementScreens, DeleteObjects),
'conditions': ('checkItems',),
'transform': ('validateItemIds', 'delete_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_sort',
'permissions': (ManageProperties,),
'transform': ('sort_control',),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start')},
{'id': 'items_up',
'permissions': (ManageProperties,),
'transform': ('validateItemIds', 'up_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_down',
'permissions': (ManageProperties,),
'transform': ('validateItemIds', 'down_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_top',
'permissions': (ManageProperties,),
'transform': ('validateItemIds', 'top_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'items_bottom',
'permissions': (ManageProperties,),
'transform': ('validateItemIds', 'bottom_control'),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents',
+ 'redirect': (ITypesTool, 'object/folderContents',
'b_start, key, reverse')},
{'id': 'set_view_filter',
'transform': ('set_filter_control',),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents')},
+ 'redirect': (ITypesTool, 'object/folderContents')},
{'id': 'clear_view_filter',
'transform': ('clear_filter_control',),
- 'redirect': ('Products.CMFCore.interfaces.ITypesTool',
- 'object/folderContents')})
+ 'redirect': (ITypesTool, 'object/folderContents')})
# helpers
@@ -183,7 +172,7 @@
@memoize
@decode
def up_info(self):
- mtool = self._getToolByInterface(IMembershipTool)
+ mtool = getUtility(IMembershipTool)
allowed = mtool.checkPermission(ListFolderContents, self.context,
'aq_parent')
if allowed:
Modified: CMF/trunk/CMFDefault/browser/metadata.py
===================================================================
--- CMF/trunk/CMFDefault/browser/metadata.py 2007-03-08 05:33:18 UTC (rev 73054)
+++ CMF/trunk/CMFDefault/browser/metadata.py 2007-03-08 08:03:18 UTC (rev 73055)
@@ -33,6 +33,7 @@
from Products.CMFCore.interfaces import IDiscussionTool
from Products.CMFCore.interfaces import IMutableDublinCore
from Products.CMFCore.interfaces import IMutableMinimalDublinCore
+from Products.CMFCore.interfaces import ITypesTool
from Products.CMFDefault.formlib.form import ContentEditFormBase
from Products.CMFDefault.formlib.schema import ProxyFieldProperty
from Products.CMFDefault.formlib.schema import SchemaAdapterBase
@@ -261,12 +262,8 @@
def handle_change_success(self, action, data):
self._handle_success(action, data)
- return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
- , 'object/metadata'
- )
+ return self._setRedirect(ITypesTool, 'object/metadata')
def handle_change_and_edit_success(self, action, data):
self._handle_success(action, data)
- return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
- , 'object/edit'
- )
+ return self._setRedirect(ITypesTool, 'object/edit')
Modified: CMF/trunk/CMFDefault/browser/utils.py
===================================================================
--- CMF/trunk/CMFDefault/browser/utils.py 2007-03-08 05:33:18 UTC (rev 73054)
+++ CMF/trunk/CMFDefault/browser/utils.py 2007-03-08 08:03:18 UTC (rev 73055)
@@ -19,16 +19,13 @@
from Globals import InitializeClass
from Products.Five import BrowserView
from Products.PythonScripts.standard import thousands_commas
+from zope.component import getUtility
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
from Products.CMFDefault.utils import html_marshal
@@ -76,25 +73,13 @@
# helpers
@memoize
- def _getTool(self, name):
- return getToolByName(self.context, name)
-
- @memoize
- def _getToolByInterface(self, iface):
- return getUtility(iface)
-
- @memoize
- def _getToolByInterfaceName(self, dotted_name):
- return getToolByInterfaceName(dotted_name)
-
- @memoize
def _checkPermission(self, permission):
- mtool = self._getToolByInterface(IMembershipTool)
+ mtool = getUtility(IMembershipTool)
return mtool.checkPermission(permission, self.context)
@memoize
def _getPortalURL(self):
- utool = self._getToolByInterface(IURLTool)
+ utool = getUtility(IURLTool)
return utool()
@memoize
@@ -103,7 +88,7 @@
@memoize
def _getDefaultCharset(self):
- ptool = self._getToolByInterface(IPropertiesTool)
+ ptool = getUtility(IPropertiesTool)
return ptool.getProperty('default_charset', None)
@memoize
@@ -128,7 +113,7 @@
# helpers
def _setRedirect(self, provider_iface, action_path, keys=''):
- provider = self._getToolByInterfaceName(provider_iface)
+ provider = getUtility(provider_iface)
try:
target = provider.getActionInfo(action_path, self.context)['url']
except ValueError:
Modified: CMF/trunk/CMFDefault/formlib/form.py
===================================================================
--- CMF/trunk/CMFDefault/formlib/form.py 2007-03-08 05:33:18 UTC (rev 73054)
+++ CMF/trunk/CMFDefault/formlib/form.py 2007-03-08 08:03:18 UTC (rev 73055)
@@ -22,12 +22,14 @@
from Products.Five.formlib.formbase import PageDisplayForm
from Products.Five.formlib.formbase import PageForm
from zope.datetime import parseDatetimetz
+from zope.component import getUtility
from zope.formlib import form
from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.locales import LoadLocaleError
from zope.i18n.locales import locales
from ZTUtils import make_query
+from Products.CMFCore.interfaces import ITypesTool
from Products.CMFDefault.utils import Message as _
from Products.CMFDefault.utils import translate
from Products.CMFDefault.browser.utils import ViewBase
@@ -63,7 +65,7 @@
self.request.locale = getLocale(request)
def _setRedirect(self, provider_iface, action_path, keys=''):
- provider = self._getToolByInterfaceName(provider_iface)
+ provider = getUtility(provider_iface)
try:
target = provider.getActionInfo(action_path, self.context)['url']
except ValueError:
@@ -147,15 +149,11 @@
def handle_change_success(self, action, data):
self._handle_success(action, data)
- return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
- , 'object/edit'
- )
+ return self._setRedirect(ITypesTool, 'object/edit')
def handle_change_and_view_success(self, action, data):
self._handle_success(action, data)
- return self._setRedirect( 'Products.CMFCore.interfaces.ITypesTool'
- , 'object/view'
- )
+ return self._setRedirect(ITypesTool, 'object/view')
class DisplayFormBase(PageDisplayForm, ViewBase):
More information about the CMF-checkins
mailing list