[Zope-CVS] CVS: Packages/Moztop/CMFMoztop - MoztopSupportTool.py:1.3

Sidnei da Silva sidnei@x3ng.com.br
Sat, 1 Mar 2003 08:22:56 -0500


Update of /cvs-repository/Packages/Moztop/CMFMoztop
In directory cvs.zope.org:/tmp/cvs-serv24939

Modified Files:
	MoztopSupportTool.py 
Log Message:
(ugly but working) proof of concept. Now you can see portal_skins folders under views and portal_types, portal_workflow and portal_skins skinpaths inside configurations.

=== Packages/Moztop/CMFMoztop/MoztopSupportTool.py 1.2 => 1.3 ===
--- Packages/Moztop/CMFMoztop/MoztopSupportTool.py:1.2	Fri Feb 28 10:24:17 2003
+++ Packages/Moztop/CMFMoztop/MoztopSupportTool.py	Sat Mar  1 08:22:25 2003
@@ -18,6 +18,7 @@
 from AccessControl import ClassSecurityInfo
 from Acquisition import aq_inner
 from Acquisition import aq_parent
+from Acquisition import aq_base
 from Globals import InitializeClass
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from OFS.SimpleItem import SimpleItem
@@ -87,7 +88,10 @@
         catalog = getToolByName(self, 'portal_catalog')
         results = []
         for r in catalog.searchResults():
-            results.append({'title':r.Title or r.title or r.id, \
+            title = getattr(aq_base(r), 'Title', None) or \
+                    getattr(aq_base(r), 'title', None) or \
+                    getattr(aq_base(r), 'id', '(no title or id)')
+            results.append({'title':title, \
                             'type':self._normalizePortalType(r.portal_type), \
                             'path':self._resourcePath(r.getURL()), \
                             'parentPath':self._resourceParentPath(r.getURL())})
@@ -95,13 +99,14 @@
         return results
 
     security.declareProtected(View, 'getParentResources')
-    def getParentResources(self):
+    def getParentResources(self, resources=None):
         """ See interface definition on moztop_support """
-
-        results = self.getResources()
+        
+        if not resources:
+            resources = self.getResources()
 
         containers = {}
-        for r in results:
+        for r in resources:
             if r['parentPath']:
                 s = containers.get(r['parentPath'], None)
                 if s is None:
@@ -117,7 +122,162 @@
 
         return containers
 
-    security.declareProtected(View, 'getRealm')
+    security.declareProtected(View, 'getViewsResources')
+    def getViewsResources(self):
+        """ See interface definition on moztop_support """
+        skins_tool = getToolByName(self, 'portal_skins')
+        title = skins_tool.title_or_id()
+        skins_url = skins_tool.absolute_url()
+        portal_type = self._normalizePortalType(skins_tool.meta_type)
+        path = self._resourcePath(skins_url)
+        parentPath = self._resourceParentPath(skins_url)
+        results = []
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+        for ob in skins_tool.objectValues():
+            results.extend(self._recurseViewsResources(ob))
+        return results
+
+    security.declareProtected(View, 'getViewsParentResources')
+    def getViewsParentResources(self):
+        """ See interface definition on moztop_support """
+
+        resources = self.getViewsResources()
+        containers = self.getParentResources(resources)
+        return containers
+
+    def _recurseViewsResources(self, ob):
+        results = []
+        title = ob.getId()
+        portal_type = self._normalizePortalType(ob.meta_type)
+        ob_path = ob.absolute_url()
+        path = self._resourcePath(ob_path)
+        parentPath = self._resourceParentPath(ob_path)
+        results.append({'title':title, \
+                        'type': portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+        if hasattr(aq_base(ob), 'objectValues'):
+            for subob in ob.objectValues():
+                results.extend(self._recurseViewsResources(subob))
+        return results
+    
+    security.declareProtected(View, 'getConfigurationResources')
+    def getConfigurationsResources(self):
+        """ See interface definition on moztop_support """
+        types_tool = getToolByName(self, 'portal_types')
+        types_url = types_tool.absolute_url()
+        results = []
+        title = types_tool.title_or_id()
+        portal_type = self._normalizePortalType(types_tool.meta_type)
+        path = self._resourcePath(types_url)
+        parentPath = self._resourceParentPath(types_url)
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+        
+        for t in types_tool.listTypeInfo():
+            title = t.Title()
+            portal_type = self._normalizePortalType(t.meta_type)
+            ob_path = '%s/%s' % (types_url, t.Title())
+            path = self._resourcePath(ob_path)
+            parentPath = self._resourceParentPath(ob_path)
+            results.append({'title':title, \
+                            'type':portal_type, \
+                            'path':path, \
+                            'parentPath':parentPath})
+
+        skins_tool = getToolByName(self, 'portal_skins')
+        skins_url = skins_tool.absolute_url()
+        title = skins_tool.title_or_id()
+        portal_type = self._normalizePortalType(skins_tool.meta_type)
+        path = self._resourcePath(skins_url)
+        parentPath = self._resourceParentPath(skins_url)
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+        
+        for skin in skins_tool.getSkinSelections():
+            title = skin
+            id = self._normalizePortalType(skin)
+            portal_type = self._normalizePortalType('Skin Path')
+            ob_path = '%s/%s' % (skins_url, id)
+            path = self._resourcePath(ob_path)
+            parentPath = self._resourceParentPath(ob_path)
+            results.append({'title':title, \
+                            'type':portal_type, \
+                            'path':path, \
+                            'parentPath':parentPath})
+
+        wf_tool = getToolByName(self, 'portal_workflow')
+        wf_url = wf_tool.absolute_url()
+        title = wf_tool.title_or_id()
+        portal_type = self._normalizePortalType(wf_tool.meta_type)
+        path = self._resourcePath(wf_url)
+        parentPath = self._resourceParentPath(wf_url)
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+
+        title = 'Available Workflows'
+        portal_type = self._normalizePortalType('Folder')
+        ob_url = '%s/%s' % (wf_url, 'workflows')
+        path = self._resourcePath(ob_url)
+        parentPath = self._resourceParentPath(ob_url)
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+
+        title = 'Type -> Workflow Mappings'
+        portal_type = self._normalizePortalType('Folder')
+        ob_url = '%s/%s' % (wf_url, 'mapping')
+        path = self._resourcePath(ob_url)
+        parentPath = self._resourceParentPath(ob_url)
+        results.append({'title':title, \
+                        'type':portal_type, \
+                        'path':path, \
+                        'parentPath':parentPath})
+        
+        for wf_id in wf_tool.getWorkflowIds():
+            ob = getattr(wf_tool, wf_id)
+            title = ob.title_or_id()
+            portal_type = self._normalizePortalType(ob.meta_type)
+            ob_path = '%s/workflows/%s' % (wf_url, id)
+            path = self._resourcePath(ob_path)
+            parentPath = self._resourceParentPath(ob_path)
+            results.append({'title':title, \
+                            'type':portal_type, \
+                            'path':path, \
+                            'parentPath':parentPath})
+
+        for t in wf_tool._listTypeInfo():
+            title = t.Title()
+            portal_type = self._normalizePortalType(t.meta_type)
+            ob_path = '%s/mapping/%s' % (wf_url, t.Title())
+            path = self._resourcePath(ob_path)
+            parentPath = self._resourceParentPath(ob_path)
+            results.append({'title':title, \
+                            'type':portal_type, \
+                            'path':path, \
+                            'parentPath':parentPath})
+
+        return results
+
+    security.declareProtected(View, 'getConfigurationsParentResources')
+    def getConfigurationsParentResources(self):
+        """ See interface definition on moztop_support """
+
+        resources = self.getConfigurationsResources()
+        containers = self.getParentResources(resources)
+        return containers
+
+    security.declarePublic('getRealm')
     def getRealm(self):
         url_tool = getToolByName(self, 'portal_url')
         portal_path = url_tool.getPortalObject().absolute_url()