[CMF-checkins] SVN: CMF/trunk/C - removed _convertActions, _guessMethodAliases and the deprecated getActionContext (bbb code for pre-1.5 ftis)

Yvo Schubbe y.2005- at wcm-solutions.de
Wed Dec 7 14:36:24 EST 2005


Log message for revision 40632:
  - removed _convertActions, _guessMethodAliases and the deprecated getActionContext (bbb code for pre-1.5 ftis)

Changed:
  U   CMF/trunk/CHANGES.txt
  U   CMF/trunk/CMFCore/TypesTool.py
  U   CMF/trunk/CMFCore/exportimport/tests/test_typeinfo.py
  U   CMF/trunk/CMFCore/tests/base/tidata.py
  U   CMF/trunk/CMFCore/tests/test_TypesTool.py
  U   CMF/trunk/CMFCore/utils.py

-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CHANGES.txt	2005-12-07 19:36:23 UTC (rev 40632)
@@ -164,6 +164,11 @@
 
   Others
 
+    - TypeInformation: Removed support for old setting formats.
+      If TypeInformation objects are initialized with keyword arguments,
+      'actions' and 'aliases' keys have to use the format introduced in
+      CMF 1.5.
+
     - CMFSetup and GenericSetup: Removed obsolete CMFSetup product.
       Added __module_aliases__ to support setup tools created with CMFSetup. 
 

Modified: CMF/trunk/CMFCore/TypesTool.py
===================================================================
--- CMF/trunk/CMFCore/TypesTool.py	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CMFCore/TypesTool.py	2005-12-07 19:36:23 UTC (rev 40632)
@@ -53,8 +53,6 @@
 from utils import _checkPermission
 from utils import _dtmldir
 from utils import _wwwdir
-from utils import cookString
-from utils import getActionContext
 from utils import getToolByName
 from utils import SimpleItemWithProperties
 from utils import UniqueObject
@@ -128,6 +126,8 @@
     def __init__(self, id, **kw):
 
         self.id = id
+        self._actions = ()
+        self._aliases = {}
 
         if not kw:
             return
@@ -145,21 +145,18 @@
         self.manage_changeProperties(**kw)
 
         actions = kw.get( 'actions', () )
-        # make sure we have a copy
-        _actions = []
         for action in actions:
-            _actions.append( action.copy() )
-        actions = tuple(_actions)
-        # We don't know if actions need conversion, so we always add oldstyle
-        # _actions and convert them.
-        self._actions = actions
-        self._convertActions()
+            self.addAction(
+                  id=action['id']
+                , name=action['title']
+                , action=action['action']
+                , condition=action.get('condition')
+                , permission=action.get( 'permissions', () )
+                , category=action.get('category', 'object')
+                , visible=action.get('visible', True)
+                )
 
-        aliases = kw.get( 'aliases', _marker )
-        if aliases is _marker:
-            self._guessMethodAliases()
-        else:
-            self.setMethodAliases(aliases)
+        self.setMethodAliases(kw.get('aliases', {}))
 
     #
     #   ZMI methods
@@ -270,41 +267,8 @@
     def listActions(self, info=None, object=None):
         """ Return a sequence of the action info objects for this type.
         """
-        if self._actions and isinstance(self._actions[0], dict):
-            self._convertActions()
-
         return self._actions or ()
 
-    security.declarePrivate( '_convertActions' )
-    def _convertActions( self ):
-        """ Upgrade dictionary-based actions.
-        """
-        aa, self._actions = self._actions, ()
-
-        for action in aa:
-
-            # Some backward compatibility stuff.
-            if not 'id' in action:
-                action['id'] = cookString(action['name'])
-
-            if not 'title' in action:
-                action['title'] = action.get('name', action['id'].capitalize())
-
-            # historically, action['action'] is simple string
-            actiontext = action.get('action').strip() or 'string:${object_url}'
-            if actiontext[:7] not in ('python:', 'string:'):
-                actiontext = 'string:${object_url}/%s' % actiontext
-
-            self.addAction(
-                  id=action['id']
-                , name=action['title']
-                , action=actiontext
-                , condition=action.get('condition')
-                , permission=action.get( 'permissions', () )
-                , category=action.get('category', 'object')
-                , visible=action.get('visible', True)
-                )
-
     security.declarePublic('constructInstance')
     def constructInstance(self, container, id, *args, **kw):
         """Build an instance of the type.
@@ -338,8 +302,6 @@
     def getMethodAliases(self):
         """ Get method aliases dict.
         """
-        if not hasattr(self, '_aliases'):
-            self._guessMethodAliases()
         aliases = self._aliases
         # for aliases created with CMF 1.5.0beta
         for key, method_id in aliases.items():
@@ -367,8 +329,6 @@
     def queryMethodID(self, alias, default=None, context=None):
         """ Query method ID by alias.
         """
-        if not hasattr(self, '_aliases'):
-            self._guessMethodAliases()
         aliases = self._aliases
         method_id = aliases.get(alias, default)
         # for aliases created with CMF 1.5.0beta
@@ -376,75 +336,6 @@
             method_id = method_id[0]
         return method_id
 
-    security.declarePrivate('_guessMethodAliases')
-    def _guessMethodAliases(self):
-        """ Guess and set Method Aliases. Used for upgrading old TIs.
-        """
-        context = getActionContext(self)
-        actions = self.listActions()
-        ordered = []
-        _dict = {}
-        viewmethod = ''
-
-        # order actions and search 'mkdir' action
-        for action in actions:
-            if action.getId() == 'view':
-                ordered.insert(0, action)
-            elif action.getId() == 'mkdir':
-                try:
-                    mkdirmethod = action.action(context).strip()
-                except AttributeError:
-                    continue
-                if mkdirmethod.startswith('/'):
-                    mkdirmethod = mkdirmethod[1:]
-                _dict['mkdir'] = mkdirmethod
-            else:
-                ordered.append(action)
-
-        # search 'view' action
-        for action in ordered:
-            perms = action.getPermissions()
-            if not perms or View in perms:
-                try:
-                    viewmethod = action.action(context).strip()
-                except (AttributeError, TypeError):
-                    break
-                if viewmethod.startswith('/'):
-                    viewmethod = viewmethod[1:]
-                if not viewmethod:
-                    viewmethod = '(Default)'
-                break
-        else:
-            viewmethod = '(Default)'
-        if viewmethod:
-            _dict['view'] = viewmethod
-
-        # search default action
-        for action in ordered:
-            try:
-                defmethod = action.action(context).strip()
-            except (AttributeError, TypeError):
-                break
-            if defmethod.startswith('/'):
-                defmethod = defmethod[1:]
-            if not defmethod:
-                break
-        else:
-            if viewmethod:
-                _dict['(Default)'] = viewmethod
-
-        # correct guessed values if we know better
-        if self.content_meta_type in ('Portal File', 'Portal Folder',
-                                      'Portal Image'):
-            _dict['(Default)'] = 'index_html'
-            if viewmethod == '(Default)':
-                _dict['view'] = 'index_html'
-        if self.content_meta_type in ('Document', 'News Item'):
-            _dict['gethtml'] = 'source_html'
-
-        self.setMethodAliases(_dict)
-        return 1
-
 InitializeClass( TypeInformation )
 
 

Modified: CMF/trunk/CMFCore/exportimport/tests/test_typeinfo.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/tests/test_typeinfo.py	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CMFCore/exportimport/tests/test_typeinfo.py	2005-12-07 19:36:23 UTC (rev 40632)
@@ -84,17 +84,17 @@
                 'view':      'foo_view',
                 },
     'actions': ({'id':     'view',
-                 'name':   'View',
+                 'title':  'View',
                  'action': 'string:${object_url}/foo_view',
                  'permissions': (View,),
                  },
                 {'id':     'edit',
-                 'name':   'Edit',
+                 'title':  'Edit',
                  'action': 'string:${object_url}/foo_edit_form',
                  'permissions': (ModifyPortalContent,),
                  },
                 {'id':     'metadata',
-                 'name':   'Metadata',
+                 'title':  'Metadata',
                  'action': 'string:${object_url}/metadata_edit_form',
                  'permissions': (ModifyPortalContent,),
                  },
@@ -116,22 +116,22 @@
                 'view':      'bar_view',
                 },
     'actions': ({'id':     'view',
-                 'name':   'View',
+                 'title':  'View',
                  'action': 'string:${object_url}/bar_view',
                  'permissions': (View,),
                  },
                 {'id':     'edit',
-                 'name':   'Edit',
+                 'title':  'Edit',
                  'action': 'string:${object_url}/bar_edit_form',
                  'permissions': (ModifyPortalContent,),
                  },
                 {'id':     'contents',
-                 'name':   'Contents',
+                 'title':  'Contents',
                  'action': 'string:${object_url}/folder_contents',
                  'permissions': (AccessContentsInformation,),
                  },
                 {'id':     'metadata',
-                 'name':   'Metadata',
+                 'title':  'Metadata',
                  'action': 'string:${object_url}/metadata_edit_form',
                  'permissions': (ModifyPortalContent,),
                  },
@@ -396,6 +396,7 @@
         return TypeInformationXMLAdapter
 
     def _populate(self, obj):
+        obj.setMethodAliases({'(Default)': 'foo', 'view': 'foo'})
         obj.addAction('foo_action', 'Foo', 'string:${object_url}/foo',
                       'python:1', (), 'Bar')
 

Modified: CMF/trunk/CMFCore/tests/base/tidata.py
===================================================================
--- CMF/trunk/CMFCore/tests/base/tidata.py	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CMFCore/tests/base/tidata.py	2005-12-07 19:36:23 UTC (rev 40632)
@@ -1,28 +1,31 @@
-ManageProperties = 'Manage properties'
 ModifyPortalContent = 'Modify portal content'
 View = 'View'
 
 FTIDATA_ACTIONS = (
       { 'id' : 'Action Tests'
       , 'meta_type' : 'Dummy'
+      , 'aliases' : {}
       , 'actions' : (
-            { 'id':'view',
+            { 'id': 'view',
               'title': 'View',
               'action':'string:',
               'permissions':('View',),
               'category':'object',
               'visible':1 }
-          , { 'name':'Edit',                    # Note: No ID passed
+          , { 'id': 'edit',
+              'title': 'Edit',
               'action':'string:${object_url}/foo_edit',
               'permissions':('Modify',),
               'category':'object',
               'visible':1 }
-          , { 'name':'Object Properties',       # Note: No ID passed
+          , { 'id': 'objectproperties',
+              'title': 'Object Properties',
               'action':'string:foo_properties',
               'permissions':('Modify',),
               'category':'object',
               'visible':1 }
-          , { 'id':'slot',
+          , { 'id': 'slot',
+              'title': 'Slot',
               'action':'string:foo_slot',
               'category':'object',
               'visible':0 }
@@ -37,6 +40,7 @@
       , 'meta_type' : 'Dummy'
       , 'product' : 'FooProduct'
       , 'factory' : 'addFoo'
+      , 'aliases' : {}
       , 'actions' : (
             { 'id': 'view',
               'title': 'View',
@@ -55,195 +59,6 @@
     ,
     )
 
-FTIDATA_CMF13 = (
-      { 'id' : 'Dummy Content 13'
-      , 'meta_type' : 'Dummy'
-      , 'description' : (
-           'Dummy Content.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'immediate_view' : 'metadata_edit_form'
-      , 'actions' : (
-            { 'id':'view',
-              'name':'View',
-              'action':'dummy_view',
-              'permissions':(View,) }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'dummy_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'metadata',
-              'name':'Metadata',
-              'action':'metadata_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          )
-      }
-    ,
-    )
-
-FTIDATA_CMF13_FOLDER = (
-      { 'id' : 'Dummy Folder 13'
-      , 'meta_type' : 'Dummy Folder'
-      , 'description' : (
-           'Dummy Folder.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'filter_content_types' : 0
-      , 'immediate_view' : 'dummy_edit_form'
-      , 'actions' : (
-            { 'id':'view',
-              'name':'View',
-              'action':'',
-              'permissions':(View,),
-              'category':'folder' }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'dummy_edit_form',
-              'permissions':(ManageProperties,),
-              'category':'folder' }
-          , { 'id':'localroles',
-              'name':'Local Roles',
-              'action':'folder_localrole_form',
-              'permissions':(ManageProperties,),
-              'category':'folder' }
-          )
-      }
-    ,
-    )
-
-FTIDATA_CMF14 = (
-      { 'id' : 'Dummy Content 14'
-      , 'meta_type' : 'Dummy'
-      , 'description' : (
-           'Dummy Content.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'immediate_view' : 'metadata_edit_form'
-      , 'actions' : (
-            { 'id':'view',
-              'name':'View',
-              'action':'string:${object_url}/dummy_view',
-              'permissions':(View,) }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'string:${object_url}/dummy_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'metadata',
-              'name':'Metadata',
-              'action':'string:${object_url}/metadata_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          )
-      }
-    ,
-    )
-
-FTIDATA_CMF14_FOLDER = (
-      { 'id' : 'Dummy Folder 14'
-      , 'meta_type' : 'Dummy Folder'
-      , 'description' : (
-           'Dummy Folder.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'filter_content_types' : 0
-      , 'immediate_view' : 'dummy_edit_form'
-      , 'actions' : (
-            { 'id':'view',
-              'name':'View',
-              'action':'string:${object_url}',
-              'permissions':(View,),
-              'category':'folder' }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'string:${object_url}/dummy_edit_form',
-              'permissions':(ManageProperties,),
-              'category':'folder' }
-          , { 'id':'localroles',
-              'name':'Local Roles',
-              'action':'string:${object_url}/folder_localrole_form',
-              'permissions':(ManageProperties,),
-              'category':'folder' }
-          )
-      }
-    ,
-    )
-
-FTIDATA_CMF14_SPECIAL = (
-      { 'id' : 'Dummy Content 14'
-      , 'meta_type' : 'Dummy'
-      , 'description' : (
-           'Dummy Content.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'immediate_view' : 'metadata_edit_form'
-      , 'actions' : (
-            { 'id':'download',
-              'name':'Download',
-              'action':'string:${object_url}/',   # Note: special default view
-              'permissions':(View,) }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'string:${object_url}/dummy_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'view',                  # Note: not first with 'View' perm
-              'name':'View',
-              'action':'string:${object_url}/dummy_view',
-              'permissions':(View,) }
-          , { 'id':'metadata',
-              'name':'Metadata',
-              'action':'string:${object_url}/metadata_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'mkdir',
-              'name':'MKDIR handler',
-              'action':'string:dummy_mkdir',
-              'category':'folder',
-              'visible':0 }
-          )
-      }
-    ,
-    )
-
-FTIDATA_CMF14_SPECIAL2 = (
-      { 'id' : 'Dummy Content 14'
-      , 'meta_type' : 'Dummy'
-      , 'description' : (
-           'Dummy Content.')
-      , 'icon' : 'dummy_icon.gif'
-      , 'product' : 'FooProduct'
-      , 'factory' : 'addFoo'
-      , 'immediate_view' : 'metadata_edit_form'
-      , 'actions' : (
-            { 'id': 'top',
-              'name': 'View Mail Archive',
-              'category': 'object',
-              'action':'python:object.getArchive().absolute_url()',
-              'permissions':(View,) }
-          , { 'id':'view',
-              'name':'View',
-              'action':"python:object.someMethod() + '/some_template.html'",
-              'permissions':(View,) }
-          , { 'id':'edit',
-              'name':'Edit',
-              'action':'string:${object_url}/dummy_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'metadata',
-              'name':'Metadata',
-              'action':'string:${object_url}/metadata_edit_form',
-              'permissions':(ModifyPortalContent,) }
-          , { 'id':'mkdir',
-              'name':'MKDIR handler',
-              'action':'python:object.getMKDIR().absolute_url()',
-              'category':'folder',
-              'visible':0 }
-          )
-      }
-    ,
-    )
-
 FTIDATA_CMF15 = (
       { 'id' : 'Dummy Content 15'
       , 'meta_type' : 'Dummy'

Modified: CMF/trunk/CMFCore/tests/test_TypesTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_TypesTool.py	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CMFCore/tests/test_TypesTool.py	2005-12-07 19:36:23 UTC (rev 40632)
@@ -43,12 +43,6 @@
 from Products.CMFCore.tests.base.testcase import SecurityTest
 from Products.CMFCore.tests.base.testcase import WarningInterceptor
 from Products.CMFCore.tests.base.tidata import FTIDATA_ACTIONS
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF13
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF13_FOLDER
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF14
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF14_FOLDER
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF14_SPECIAL
-from Products.CMFCore.tests.base.tidata import FTIDATA_CMF14_SPECIAL2
 from Products.CMFCore.tests.base.tidata import FTIDATA_CMF15
 from Products.CMFCore.tests.base.tidata import FTIDATA_DUMMY
 from Products.CMFCore.tests.base.tidata import STI_SCRIPT
@@ -300,111 +294,7 @@
         self.assertEqual(ti._actions[1].action.text, wanted_actions_text1)
         self.assertEqual(ti._actions[2].action.text, wanted_actions_text2)
 
-    def test_CMF13_content_migration(self):
 
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF13[0] )
-        self._checkContentTI(ti)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-        ti._actions = FTIDATA_CMF13[0]['actions']
-        self.failUnless( isinstance(ti._actions[0], dict) )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self._checkContentTI(ti)
-
-    def test_CMF13_folder_migration(self):
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF13_FOLDER[0] )
-        self._checkFolderTI(ti)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-        ti._actions = FTIDATA_CMF13_FOLDER[0]['actions']
-        self.failUnless( isinstance(ti._actions[0], dict) )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self._checkFolderTI(ti)
-
-    def test_CMF14_content_migration(self):
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF14[0] )
-        self._checkContentTI(ti)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self._checkContentTI(ti)
-
-    def test_CMF14_folder_migration(self):
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF14_FOLDER[0] )
-        self._checkFolderTI(ti)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self._checkFolderTI(ti)
-
-    def test_CMF14_special_migration(self):
-        wanted = { 'view': 'dummy_view', 'mkdir': 'dummy_mkdir' }
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF14_SPECIAL[0] )
-        self.assertEqual(ti._aliases, wanted)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self.assertEqual(ti._aliases, wanted)
-
-    def test_CMF14_special2_migration(self):
-        wanted = {}
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF14_SPECIAL2[0] )
-        self.assertEqual(ti._aliases, wanted)
-
-        # simulate old FTI
-        del ti._aliases
-        self.failIf( hasattr(ti, '_aliases') )
-
-        # migrate FTI
-        ti.queryMethodID('view')
-        self.assertEqual(ti._aliases, wanted)
-
-    def test_CMF150beta_content_migration(self):
-
-        # use old FTI Data
-        ti = self._makeInstance( **FTIDATA_CMF14[0] )
-        self._checkContentTI(ti)
-
-        # simulate old FTI
-        ti._aliases = { 'view': ('dummy_view',),
-                        '(Default)': ('dummy_view',) }
-
-        # migrate FTI
-        ti.getMethodAliases()
-        self._checkContentTI(ti)
-
-
 class FTIDataTests( TypeInfoTests ):
 
     def _makeInstance(self, id, **kw):

Modified: CMF/trunk/CMFCore/utils.py
===================================================================
--- CMF/trunk/CMFCore/utils.py	2005-12-07 18:58:57 UTC (rev 40631)
+++ CMF/trunk/CMFCore/utils.py	2005-12-07 19:36:23 UTC (rev 40632)
@@ -44,8 +44,6 @@
 from OFS.PropertyManager import PropertyManager
 from OFS.PropertySheets import PropertySheets
 from OFS.SimpleItem import SimpleItem
-from Products.PageTemplates.Expressions import getEngine
-from Products.PageTemplates.Expressions import SecureModuleImporter
 from thread import allocate_lock
 
 from exceptions import AccessControl_Unauthorized
@@ -154,24 +152,6 @@
 
     return context.user.allowed(obj, roles)
 
-security.declarePublic( 'getActionContext' )
-def getActionContext( self ):
-    # getActionContext is deprecated and will be removed as soon as the
-    # backwards compatibility code in TypeInformation._guessMethodAliases is
-    # removed.
-    data = { 'object_url'   : ''
-           , 'folder_url'   : ''
-           , 'portal_url'   : ''
-           , 'object'       : None
-           , 'folder'       : None
-           , 'portal'       : None
-           , 'nothing'      : None
-           , 'request'      : getattr( self, 'REQUEST', None )
-           , 'modules'      : SecureModuleImporter
-           , 'member'       : None
-           }
-    return getEngine().getContext( data )
-
 # If Zope ever provides a call to getRolesInContext() through
 # the SecurityManager API, the method below needs to be updated.
 security.declarePrivate('_limitGrantedRoles')



More information about the CMF-checkins mailing list