[CMF-checkins] CVS: CMF/CMFCore - DynamicType.py:1.16.20.1 PortalFolder.py:1.46.8.1 TypesTool.py:1.55.2.1 utils.py:1.40.8.1

Yvo Schubbe schubbe@web.de
Sun, 22 Jun 2003 12:18:14 -0400


Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv12778/CMFCore

Modified Files:
      Tag: yuppie-ti_aliases-branch
	DynamicType.py PortalFolder.py TypesTool.py utils.py 
Log Message:
'first cut' of ti aliases.
There is still a lot to do, but at least it seems to work.
Feedback is welcome!


=== CMF/CMFCore/DynamicType.py 1.16 => 1.16.20.1 ===
--- CMF/CMFCore/DynamicType.py:1.16	Thu Feb 13 03:28:42 2003
+++ CMF/CMFCore/DynamicType.py	Sun Jun 22 12:17:43 2003
@@ -93,4 +93,20 @@
     security.declarePublic('icon')
     icon = getIcon  # For the ZMI
 
+    def __before_publishing_traverse__(self, arg1, arg2=None):
+        """ Pre-traversal hook.
+        """
+        # XXX hack around a bug(?) in BeforeTraverse.MultiHook
+        REQUEST = arg2 or arg1
+
+        stack = REQUEST['TraversalRequestNameStack']
+        key = stack and stack[-1] or '(Default)'
+        alias = self.getTypeInfo().getAlias(key)
+        if alias:
+            if key is not '(Default)':
+                stack.pop()
+            for id in alias:
+                if id is not '(Default)':
+                    stack.append(id)
+
 InitializeClass(DynamicType)


=== CMF/CMFCore/PortalFolder.py 1.46 => 1.46.8.1 ===
--- CMF/CMFCore/PortalFolder.py:1.46	Fri May  9 17:40:23 2003
+++ CMF/CMFCore/PortalFolder.py	Sun Jun 22 12:17:43 2003
@@ -49,7 +49,7 @@
                          }
                        , { 'id'            : 'edit'
                          , 'name'          : 'Edit'
-                         , 'action': 'string:${object_url}/folder_edit_form'
+                         , 'action': 'string:${object_url}/edit'
                          , 'permissions'   : (ManageProperties,)
                          , 'category'      : 'folder'
                          }
@@ -61,6 +61,10 @@
                          , 'category'      : 'folder'
                          }
                        )
+  , 'aliases'        : {'(Default)':'index_html',
+                        'view':'index_html',
+                        'index.html':'index_html',
+                        'edit':'folder_edit_form'}
   }
 ,
 )


=== CMF/CMFCore/TypesTool.py 1.55 => 1.55.2.1 ===
--- CMF/CMFCore/TypesTool.py:1.55	Wed Jun 11 07:11:18 2003
+++ CMF/CMFCore/TypesTool.py	Sun Jun 22 12:17:43 2003
@@ -25,6 +25,7 @@
 from Acquisition import aq_get
 from zLOG import LOG, WARNING, ERROR
 from OFS.Folder import Folder
+from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 import Products
 
 from interfaces.portal_types import ContentTypeInformation as ITypeInformation
@@ -40,6 +41,7 @@
 from utils import SimpleItemWithProperties
 from utils import _dtmldir
 from utils import _checkPermission
+from utils import _wwwdir
 from utils import cookString
 from utils import getActionContext
 
@@ -145,7 +147,9 @@
                           , visible=action.get( 'visible', 1 )
                           )
 
-        
+        aliases = kw.get( 'aliases', {} )
+        self.setAliases(aliases)
+
 
     #
     #   Accessors
@@ -312,6 +316,48 @@
 
         return ob
 
+    security.declareProtected(ManagePortal, 'getAliases')
+    def getAliases(self):
+        """ Get aliases dict.
+        """
+        return getattr( self, 'aliases', {} )
+
+    security.declareProtected(ManagePortal, 'setAliases')
+    def setAliases(self, aliases):
+        """ Set aliases dict.
+        """
+        dict = {}
+        for k, v in aliases.items():
+            v = v.strip()
+            if v:
+                path = v.split('/')
+                path.reverse()
+                dict[ k.strip() ] = tuple(path)
+        if not self.getAliases() == dict:
+            self.aliases = dict
+            return 1
+        else:
+            return 0
+
+    security.declarePublic('getAlias')
+    def getAlias(self, key):
+        """ Get alias path for key in reverse order.
+        
+        Returns -- Tuple of IDs
+        """
+        aliases = getattr( self, 'aliases', {} )
+        return aliases.get( key, () )
+
+    security.declarePublic('getAliasURL')
+    def getAliasURL(self, key):
+        """ Get alias for key.
+        
+        Returns -- Slash-separated string
+        """
+        path = list( self.getAlias(key) )
+        path.reverse()
+        return '/'.join(path)
+
 InitializeClass( TypeInformation )
 
 
@@ -508,11 +554,14 @@
 
     security = ClassSecurityInfo()
 
-    manage_options = ( Folder.manage_options +
-                      ActionProviderBase.manage_options +
-                      ({ 'label' : 'Overview', 'action' : 'manage_overview' }
-                     , 
-                     ))
+    manage_options = ( Folder.manage_options[:1]
+                     + ( {'label':'Aliases',
+                          'action':'manage_aliases'}, )
+                     + ActionProviderBase.manage_options
+                     + ( {'label':'Overview',
+                          'action':'manage_overview'}, )
+                     + Folder.manage_options[1:]
+                     )
 
     #
     #   ZMI methods
@@ -520,6 +569,9 @@
     security.declareProtected(ManagePortal, 'manage_overview')
     manage_overview = DTMLFile( 'explainTypesTool', _dtmldir )
 
+    security.declareProtected(ManagePortal, 'manage_aliases')
+    manage_aliases = PageTemplateFile( 'typesAliases.zpt', _wwwdir )
+
     def all_meta_types(self):
         """Adds TypesTool-specific meta types."""
         all = TypesTool.inheritedAttribute('all_meta_types')(self)
@@ -618,6 +670,25 @@
         if RESPONSE is not None:
             RESPONSE.redirect('%s/manage_main' % self.absolute_url())
 
+    security.declareProtected(ManagePortal, 'manage_setTIAliases')
+    def manage_setTIAliases(self, REQUEST):
+        """ Config aliases.
+        """
+        form = REQUEST.form
+        aliases = {}
+        for k, v in form['aliases'].items():
+            v = v.strip()
+            if v:
+                aliases[k] = v
+        
+        for ti in self.listTypeInfo():
+            dict = {}
+            for k, v in form[ ti.getId() ].items():
+                if aliases.has_key(k):
+                    dict[ aliases[k] ] = v
+            ti.setAliases(dict)
+        REQUEST.RESPONSE.redirect('%s/manage_aliases' % self.absolute_url())
+
     security.declareProtected(AccessContentsInformation, 'getTypeInfo')
     def getTypeInfo( self, contentType ):
         """
@@ -737,5 +808,18 @@
                 actions.extend( type_info.listActions( info ) )
 
         return actions
+
+    security.declareProtected(ManagePortal, 'listAliasKeys')
+    def listAliasKeys(self):
+        """ List defined aliases.
+        """
+        dict = {}
+        for ti in self.listTypeInfo():
+            aliases = ti.getAliases()
+            for alias, v in aliases.items():
+                dict[alias] = 1
+        rval = dict.keys()
+        rval.sort()
+        return rval
 
 InitializeClass( TypesTool )


=== CMF/CMFCore/utils.py 1.40 => 1.40.8.1 ===
--- CMF/CMFCore/utils.py:1.40	Fri May  9 17:40:23 2003
+++ CMF/CMFCore/utils.py	Sun Jun 22 12:17:43 2003
@@ -49,6 +49,7 @@
 security = ModuleSecurityInfo( 'Products.CMFCore.utils' )
 
 _dtmldir = os_path.join( package_home( globals() ), 'dtml' )
+_wwwdir = os.path.join( package_home( globals() ), 'www' )
 
 #
 #   Simple utility functions, callable from restricted code.